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.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,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 A4026C43331 for ; Fri, 27 Mar 2020 16:56:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 687B62074A for ; Fri, 27 Mar 2020 16:56:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 687B62074A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F40516B000E; Fri, 27 Mar 2020 12:56:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F178C6B0010; Fri, 27 Mar 2020 12:56:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E54686B0032; Fri, 27 Mar 2020 12:56:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id CC2E86B000E for ; Fri, 27 Mar 2020 12:56:12 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B059540D0 for ; Fri, 27 Mar 2020 16:56:12 +0000 (UTC) X-FDA: 76641744984.11.seat79_19077939d042e X-HE-Tag: seat79_19077939d042e X-Filterd-Recvd-Size: 3649 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 16:56:11 +0000 (UTC) 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 16AFF1FB; Fri, 27 Mar 2020 09:56:11 -0700 (PDT) Received: from [172.16.1.108] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9FF4A3F71E; Fri, 27 Mar 2020 09:56:09 -0700 (PDT) Subject: Re: [PATCH 1/3] kexec: Prevent removal of memory in use by a loaded kexec image To: David Hildenbrand Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Eric Biederman , Andrew Morton , Catalin Marinas , Will Deacon , Anshuman Khandual , Bhupesh Sharma References: <20200326180730.4754-1-james.morse@arm.com> <20200326180730.4754-2-james.morse@arm.com> <321e6bf7-e898-7701-dd60-6c25237ff9cd@redhat.com> From: James Morse Openpgp: preference=signencrypt Message-ID: Date: Fri, 27 Mar 2020 16:56:04 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <321e6bf7-e898-7701-dd60-6c25237ff9cd@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 David, On 3/27/20 9:30 AM, David Hildenbrand wrote: > On 26.03.20 19:07, James Morse wrote: >> An image loaded for kexec is not stored in place, instead its segments >> are scattered through memory, and are re-assembled when needed. In the >> meantime, the target memory may have been removed. >> >> Because mm is not aware that this memory is still in use, it allows it >> to be removed. >> >> Add a memory notifier to prevent the removal of memory regions that >> overlap with a loaded kexec image segment. e.g., when triggered from the >> Qemu console: >> | kexec_core: memory region in use >> | memory memory32: Offline failed. >> >> Signed-off-by: James Morse >> --- >> kernel/kexec_core.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 56 insertions(+) >> >> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c >> index c19c0dad1ebe..ba1d91e868ca 100644 >> --- a/kernel/kexec_core.c >> +++ b/kernel/kexec_core.c > E.g., in kernel/kexec_core.c:kimage_alloc_pages() > > "SetPageReserved(pages + i);" > > Pages that are reserved cannot get offlined. How are you able to trigger > that before this patch? (where is the allocation path for kexec, which > will not set the pages reserved?) This sets page reserved on the memory it gets back from alloc_pages() in kimage_alloc_pages(). This is when you load the image[0]. The problem I see is for the target or destination memory once you execute the image. Once machine_kexec() runs, it tries to write to this, assuming it is still present... How can I make the commit message clearer? 're-assembled' and 'target memory' aren't quite cutting it, is there are a correct term to use? (destination?) Thanks, James [0] Just to convince myself: | kimage_alloc_pages+0x30/0x15c | kimage_alloc_page+0x210/0x7d8 | kimage_load_segment+0x14c/0x8c8 | __arm64_sys_kexec_load+0x4f0/0x720 | do_el0_svc+0x13c/0x3c0 | el0_sync_handler+0x9c/0x3c0 | el0_sync+0x158/0x180