From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 386B3C433EF for ; Tue, 28 Jun 2022 23:51:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2C056B0071; Tue, 28 Jun 2022 19:51:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADB4A6B0072; Tue, 28 Jun 2022 19:51:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CA368E0001; Tue, 28 Jun 2022 19:51:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8BF016B0071 for ; Tue, 28 Jun 2022 19:51:09 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5AEE8604DE for ; Tue, 28 Jun 2022 23:51:09 +0000 (UTC) X-FDA: 79629293058.15.C6A81D9 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf14.hostedemail.com (Postfix) with ESMTP id 73CF3100024 for ; Tue, 28 Jun 2022 23:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656460268; x=1687996268; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=dI3HshvmacGZNIxLwiGqhbPCAPM3w/IVmJ97bcAXWCk=; b=elUgXQ+eaWXqS3tP1wxNsGwjY0GRVB79Xr2zVo3PR1brbq3U7fqTjXv2 MFuCWmbqx2LbM+Nr+YmsR0N1MkEOfhSG6CAX9DYmeVaN/wfEW311tZyHX 12r+l+MxJn4daXPRh/hXmEhQE76SLphqb0Gy5BKke/T/iAmtZ6W9/qU8h q+JcAl011Se5MoRtaisW2d9VbOHy3xbyjeblWVXJsfL7OEEWyb/TfEvo0 NsLJlr4jgjYzf8x9F/bjN0atLaE8OPLOUfJMcK8KWKd2BWfxHkpK+bImk Q4L9cKXEUHfj649RE9C0FQDGGgsczZiQD3AQyp24LtMTKVsM8uZwmnUO9 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="368190798" X-IronPort-AV: E=Sophos;i="5.92,230,1650956400"; d="scan'208";a="368190798" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 16:51:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,230,1650956400"; d="scan'208";a="617363723" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 28 Jun 2022 16:50:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 95514CE; Wed, 29 Jun 2022 02:51:05 +0300 (EEST) Date: Wed, 29 Jun 2022 02:51:05 +0300 From: "Kirill A. Shutemov" To: "Eric W. Biederman" Cc: Dave Hansen , Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Varad Gautam , Dario Faggioli , Mike Rapoport , David Hildenbrand , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org Subject: Re: [PATCHv7 11/14] x86: Disable kexec if system has unaccepted memory Message-ID: <20220628235105.z6ytdzxofrdkjti4@black.fi.intel.com> References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> <20220614120231.48165-12-kirill.shutemov@linux.intel.com> <6be29d38-5c93-7cc9-0de7-235d3f83773c@intel.com> <87a6a3aw50.fsf@email.froward.int.ebiederm.org> <20220624020005.txpxlsbjbebf6oq4@black.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220624020005.txpxlsbjbebf6oq4@black.fi.intel.com> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656460268; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=s8KE52/FDi52tZqWsQhhi7qMpLAHzhQCw3mA19AEtWc=; b=C7KOw4oOF3+Dj5Mt5B9wGSyY1JSnj2HzqkCBf9C48ZOsl8u+H6Ys/2BKtRDmDUDHLO1lTC EizRrEFnWYk2wzVPdK4BEuKIHQKNrWarueQW2ACPaTXeMk9xScakaWQfWFbquE4iusruh/ x9Wkh7Fj20IUwX5CCQ0dmFwe2XHv4JE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=elUgXQ+e; spf=none (imf14.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.43) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656460269; a=rsa-sha256; cv=none; b=31oeT3BY2LQKw9O7YbjHWffXMd+vJpcIpZjuQ5P2r1yZY2TqFTjq7nrY7HLjgYXCz7IgAw mSeFpGKj6ZaV4e6hi3u6VXsJvyr1OJERY0s7IFQSOizAuRdViw5U84I4A7t8Zr7eqhWISe iByCfB2IRbXLTdGdgceMpOJeJRRx+6k= Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=elUgXQ+e; spf=none (imf14.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.43) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: r6oao7538u8sk3ea3bjwz95zn1rcwnez X-Rspamd-Queue-Id: 73CF3100024 X-HE-Tag: 1656460268-765154 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jun 24, 2022 at 05:00:05AM +0300, Kirill A. Shutemov wrote: > > If there is some deep and fundamental why this can not be supported > > then it probably makes sense to put some code in the arch_kexec_load > > hook that verifies that deep and fundamental reason is present. > > Sounds straight-forward. I can do this. What about the patch below? >From 0b758600e1eef5525f2a46630ab3559f118a272a Mon Sep 17 00:00:00 2001 From: "Kirill A. Shutemov" Date: Tue, 10 May 2022 19:02:18 +0300 Subject: [PATCH] x86: Disable kexec if system has unaccepted memory On kexec, the target kernel has to know what memory has been accepted. Information in EFI map is out of date and cannot be used. boot_params.unaccepted_memory can be used to pass the bitmap between two kernels on kexec, but the use-case is not yet implemented. Disable kexec on machines with unaccepted memory for now. Signed-off-by: Kirill A. Shutemov --- arch/x86/mm/unaccepted_memory.c | 16 ++++++++++++++++ include/linux/kexec.h | 2 ++ kernel/kexec.c | 4 ++++ kernel/kexec_core.c | 5 +++++ kernel/kexec_file.c | 4 ++++ 5 files changed, 31 insertions(+) diff --git a/arch/x86/mm/unaccepted_memory.c b/arch/x86/mm/unaccepted_memory.c index 566c3a72aee8..529c3fd1dab3 100644 --- a/arch/x86/mm/unaccepted_memory.c +++ b/arch/x86/mm/unaccepted_memory.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only +#include #include #include #include @@ -98,3 +99,18 @@ bool range_contains_unaccepted_memory(phys_addr_t start, phys_addr_t end) return ret; } + +#ifdef CONFIG_KEXEC_CORE +int arch_kexec_load(void) +{ + if (!boot_params.unaccepted_memory) + return 0; + + /* + * TODO: Information on memory acceptance status has to be communicated + * between kernel. + */ + pr_warn_once("Disable kexec: not yet supported on systems with unaccepted memory\n"); + return -EOPNOTSUPP; +} +#endif diff --git a/include/linux/kexec.h b/include/linux/kexec.h index ce6536f1d269..dfd9493d0b4b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -396,6 +396,8 @@ void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); void arch_kexec_protect_crashkres(void); void arch_kexec_unprotect_crashkres(void); +int arch_kexec_load(void); + #ifndef page_to_boot_pfn static inline unsigned long page_to_boot_pfn(struct page *page) { diff --git a/kernel/kexec.c b/kernel/kexec.c index b5e40f069768..352b3742f07a 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -195,6 +195,10 @@ static inline int kexec_load_check(unsigned long nr_segments, { int result; + result = arch_kexec_load(); + if (result) + return result; + /* We only trust the superuser with rebooting the system. */ if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) return -EPERM; diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 4d34c78334ce..4d51b9271f6b 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1238,3 +1238,8 @@ void __weak arch_kexec_protect_crashkres(void) void __weak arch_kexec_unprotect_crashkres(void) {} + +int __weak arch_kexec_load(void) +{ + return 0; +} diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 145321a5e798..d531df94ffbb 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -324,6 +324,10 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, int ret = 0, i; struct kimage **dest_image, *image; + ret = arch_kexec_load(); + if (ret) + return ret; + /* We only trust the superuser with rebooting the system. */ if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) return -EPERM; -- Kirill A. Shutemov