Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2211016yba; Mon, 22 Apr 2019 02:30:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWh15kbcsYIjOPKOfhUa0/sq4qq/WrV0ZVJq6n/7HSyzzDLfada+xdsEoQWa3mAz+EnBu3 X-Received: by 2002:a63:6cc4:: with SMTP id h187mr5376291pgc.437.1555925442523; Mon, 22 Apr 2019 02:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555925442; cv=none; d=google.com; s=arc-20160816; b=H3XZKnwENHxgz2ZrKkwC6yUSKawM/h1X6474fzhLnzQa9nTe0n5n4JTiqAGv14O600 y/Mbw5zPZ2WrFamlG3jEGHHkdBM3TAWvsFjlEKEGWPLvM+pjlAgQV1N318AZgi8+X5Xv Y050+GWRL4JyAJYfx0aA3lCKxUGw0gEKpyVdDUyEqFnPeDEy/VIqMshYClcgyBVLeE9i izv+7OEoSlwVqNopAe0fLE81YBCuiGD5daMd/f/owhBAsa2AerwJJtwwq2ALovhPsVMC rrdzSkCHBjMTz7H4YWKu8XuBxGi6lDOA2pQwUnKBY1ldtiUzs7sTcVhNURr39Q2P96Kk kN2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=JlAY2JglMYg9WICqHWPutCtIvlSM3j5jExnEToK1CMc=; b=uyGJ24h74mx24qfFUdS4MvQIe3YTf/xWFjMjPHIjByqxIxKhDkLyrONYTo6rgHfrQm 8Wr9VTPwHQbOdJeejSF8/CxWRvqm9ejg/+OtBmT7pB50O+DYcGc5Tg6n4GLhJj6QcMAL lurASXVMoiu5a7c0uEqzFZ0IxvQDr343alG6+jYXjeq539MrkQ/90aB3r0TjmenzlDPi nUZU5VIra7fJaClQ2BrKg44mQi0xVcE39QMcVCfrQ0n/Vs+zGd98IYN+HIh8jH1V2uS5 SaL4f7OSL2AOzhUFEc/ntUx2opHnlZtBbwAeyyN0y90xuKk1h1dfC2oslntHVCTGEeG9 XnaA== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w23si13146710plk.109.2019.04.22.02.30.26; Mon, 22 Apr 2019 02:30:42 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726181AbfDVJ3M (ORCPT + 99 others); Mon, 22 Apr 2019 05:29:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49494 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbfDVJ3M (ORCPT ); Mon, 22 Apr 2019 05:29:12 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 436BE99DDC; Mon, 22 Apr 2019 09:29:12 +0000 (UTC) Received: from kasong-rh-laptop.nay.redhat.com (unknown [10.66.128.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id A87FA26FC3; Mon, 22 Apr 2019 09:29:06 +0000 (UTC) From: Kairui Song To: linux-kernel@vger.kernel.org Cc: Borislav Petkov , Thomas Gleixner , Junichi Nomura , Chao Fan , Baoquan He , Dave Young , "x86@kernel.org" , "kexec@lists.infradead.org" , Kairui Song Subject: [PATCH] x86/kexec: always ensure EFI systab region is mapped Date: Mon, 22 Apr 2019 17:28:04 +0800 Message-Id: <20190422092804.15534-1-kasong@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 22 Apr 2019 09:29:12 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a fix needed for: "x86/boot: Use efi_setup_data for searching RSDP on kexec-ed kernels", that patch cause kexec to reset the system on some machines. The reason is the systab region is not mapped by the identity mapping provided by kexec. Currently kexec only create identity mapping for mem regions, wihch won't cover the systab. So second kernel will be accessing a not mapped memory region and cause fault. But as kexec tend to pad the map region up to PUD size, the systab could be included in the map by accident, so it worked on some machines, but that will be broken easily and unstable. To fix it just treat systab specially, always map the systab region unconditionally on EFI systems as long as there is a valid systab address. Signed-off-by: Kairui Song --- arch/x86/kernel/machine_kexec_64.c | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index ceba408ea982..d5da54893f97 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -113,6 +114,37 @@ static void *alloc_pgt_page(void *data) return p; } +#ifdef CONFIG_EFI +static int init_efi_systab_pgtable(struct x86_mapping_info *info, + pgd_t *level4p) +{ + unsigned long mstart, mend; + + if (!efi_enabled(EFI_BOOT)) + return 0; + + mstart = (boot_params.efi_info.efi_systab | + ((u64)boot_params.efi_info.efi_systab_hi<<32)); + + if (efi_enabled(EFI_64BIT)) + mend = mstart + sizeof(efi_system_table_64_t); + else + mend = mstart + sizeof(efi_system_table_32_t); + + if (mstart) + return kernel_ident_mapping_init(info, + level4p, mstart, mend); + + return 0; +} +#else +static inline int init_efi_systab_pgtable(struct x86_mapping_info *info, + pgd_t *level4p) +{ + return 0; +} +#endif + static int init_pgtable(struct kimage *image, unsigned long start_pgtable) { struct x86_mapping_info info = { @@ -159,6 +191,14 @@ static int init_pgtable(struct kimage *image, unsigned long start_pgtable) return result; } + /* + * Prepare EFI systab mapping for kexec kernel, systab is not + * covered by pfn_mapped. + */ + result = init_efi_systab_pgtable(&info, level4p); + if (result) + return result; + return init_transition_pgtable(image, level4p); } -- 2.20.1