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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F3DDC4724C for ; Fri, 1 May 2020 16:58:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4AB3F2173E for ; Fri, 1 May 2020 16:58:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SUWGslG3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4AB3F2173E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=+D5f8Q9JPB6DxQlXyRZm4O4TunnOcEa2Da2LsIRrXbI=; b=SUWGslG3fKrsU7 nBHrF8pAZHRUX3yS8M+tQs/uoqfCh1F6YUCHpkfNVS8xyEbQOUo7OAyIWENQIjrW0U6JZAM5xQmzn Y7hnRe9v9zEk90iC5Ap8nbaYSHnJOenQLSj3h+j/+E+5PUuOPxMXOFzpKfOuLVljcPA7CFMxcQYP7 Aqo8MQYsCO4Hbo7hHPaLe5bu284hpZqZ3/QNwic61B/foLGe9GrII9QdmXjgyqovUNvsDkEOsf9ms ah3AZUTRivlzuj5KS0JVV+xUMAHVPpJvT/sIHvfFX9Djh4/bakfYuBJkm7jqPZiUGJcMrwUZk1oqr TKCSra6sflsWSJ75PK2A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUYz7-0003J9-Lp; Fri, 01 May 2020 16:57:57 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUYz4-0003Hn-Hs; Fri, 01 May 2020 16:57:56 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DA28F30E; Fri, 1 May 2020 09:57:53 -0700 (PDT) Received: from melchizedek.cambridge.arm.com (melchizedek.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C0BAE3F305; Fri, 1 May 2020 09:57:52 -0700 (PDT) From: James Morse To: kexec@lists.infradead.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] kexec: Discard loaded image on memory hotplug Date: Fri, 1 May 2020 17:57:01 +0100 Message-Id: <20200501165701.24587-1-james.morse@arm.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200501_095754_634917_BC5A776D X-CRM114-Status: GOOD ( 13.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: James Morse , Dave Young , Eric Biederman , Baoquan He , David Hildenbrand Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On x86, the kexec payload contains a copy of the current memory map. If memory is added or removed, this copy of the memory map becomes stale. Getting this wrong may prevent the next kernel from booting. The first kernel may die if it tries to re-assemble the next kernel in memory that has been removed. Discard the loaded kexec image when the memory map changes, user-space should reload it. Kdump is unaffected, as it is placed within the crashkernel reserved memory area and only uses this memory. The stale memory map may affect generation of the vmcore, but the kdump kernel should be in a position to validate it. Signed-off-by: James Morse --- This patch obsoletes: * kexec/memory_hotplug: Prevent removal and accidental use https://lore.kernel.org/linux-arm-kernel/20200326180730.4754-1-james.morse@arm.com/ kernel/kexec_core.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index c19c0dad1ebe..e1901e5bd4b5 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -22,10 +23,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -1219,3 +1222,40 @@ void __weak arch_kexec_protect_crashkres(void) void __weak arch_kexec_unprotect_crashkres(void) {} + +/* + * If the memory layout changes, any loaded kexec image should be evicted + * as it may contain a copy of the (now stale) memory map. This also means + * we don't need to check the memory is still present when re-assembling the + * new kernel at machine_kexec() time. + */ +static int mem_change_cb(struct notifier_block *nb, unsigned long action, + void *data) +{ + /* + * Actions are either a change, or a change being cancelled. + * A second discard for 'cancel's is harmless. + */ + + mutex_lock(&kexec_mutex); + if (kexec_image) { + kimage_free(xchg(&kexec_image, NULL)); + pr_warn("loaded image discarded due to memory hotplug"); + } + mutex_unlock(&kexec_mutex); + + return NOTIFY_DONE; +} + +static struct notifier_block mem_change_nb = { + .notifier_call = mem_change_cb, +}; + +static int __init register_mem_change_cb(void) +{ + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + return register_memory_notifier(&mem_change_nb); + + return 0; +} +device_initcall(register_mem_change_cb); -- 2.26.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel