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=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 00DDBC54E4B for ; Sun, 10 May 2020 13:07:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8CF822082E for ; Sun, 10 May 2020 13:07:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G5iUDSqC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CF822082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EEC0C8E001A; Sun, 10 May 2020 09:06:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9CE18E0001; Sun, 10 May 2020 09:06:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB22B8E001A; Sun, 10 May 2020 09:06:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0100.hostedemail.com [216.40.44.100]) by kanga.kvack.org (Postfix) with ESMTP id C13258E0001 for ; Sun, 10 May 2020 09:06:59 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 718FE180AD817 for ; Sun, 10 May 2020 13:06:59 +0000 (UTC) X-FDA: 76800834558.22.crate82_2b792e1d7d18 X-HE-Tag: crate82_2b792e1d7d18 X-Filterd-Recvd-Size: 5546 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Sun, 10 May 2020 13:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589116018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zn8phY1eUuG85M8J+rkrnBbdy6ngc2Zuh3XucQHcmE0=; b=G5iUDSqCcwxzXpBH7eBlI1ieoThugqMWcUSztiF6HALG68tQd4PG9/3HUZo+PfBqq2LvnL xA/HBJkmwfomKaHzIe6sWajmplwRpOQscdnO90AZPeT7pY/2cjZTM8WA+k5colyRZbFZbr zbo9mOgKjxvfwSdBpa3HYeFAJyjv3lc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-mDPZA4fiNgK4Zyaaw5aQGQ-1; Sun, 10 May 2020 09:06:56 -0400 X-MC-Unique: mDPZA4fiNgK4Zyaaw5aQGQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FD0A80058A; Sun, 10 May 2020 13:06:55 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2F3B60BF3; Sun, 10 May 2020 13:06:48 +0000 (UTC) Date: Sun, 10 May 2020 21:06:46 +0800 From: Baoquan He To: James Morse Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Eric Biederman , David Hildenbrand , Dave Young Subject: Re: [PATCH] kexec: Discard loaded image on memory hotplug Message-ID: <20200510130646.GA4922@MiWiFi-R3L-srv> References: <20200501165701.24587-1-james.morse@arm.com> MIME-Version: 1.0 In-Reply-To: <20200501165701.24587-1-james.morse@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: Hi James, On 05/01/20 at 05:57pm, James Morse wrote: > 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. As we have discarded in your patches thread, adding a kexec service to reload kexec should fix this. Do you mean there's still another issue that we need fix? I may not get it clearly. > > 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 > >