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=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 4C692C43331 for ; Mon, 30 Mar 2020 13:13:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F3A3220733 for ; Mon, 30 Mar 2020 13:13:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gN4o4Buk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3A3220733 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 821B76B0032; Mon, 30 Mar 2020 09:13:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D2236B0037; Mon, 30 Mar 2020 09:13:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69AD88E0001; Mon, 30 Mar 2020 09:13:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id 4B9126B0032 for ; Mon, 30 Mar 2020 09:13:36 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 29348180AD801 for ; Mon, 30 Mar 2020 13:13:36 +0000 (UTC) X-FDA: 76652070432.02.moon79_243c1b63ef18 X-HE-Tag: moon79_243c1b63ef18 X-Filterd-Recvd-Size: 10365 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Mon, 30 Mar 2020 13:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585574014; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Ao3zXk94r5n1r1NdUT1EgWM2jGWvojEWgL79T2zxRjI=; b=gN4o4BukZBq4upYfm90djFXS0uHd6jV7seawDtU6VJHPPT0pGRgU9MYWSQhaxJoXj6Eajr d6hnEPBxr5EfKERmkx7tyWp4b+tbramL5RLb5xfoakyK3ce1MBpmZIsDdIUKD2XG6he1rB gncqPLKk2bpaMiM7cFG9DYA9SVJZacM= 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-76-cDskFl0hPaKRYJuBxlagJA-1; Mon, 30 Mar 2020 09:13:33 -0400 X-MC-Unique: cDskFl0hPaKRYJuBxlagJA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EFD1107ACCD; Mon, 30 Mar 2020 13:13:31 +0000 (UTC) Received: from [10.36.113.227] (ovpn-113-227.ams2.redhat.com [10.36.113.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C9295C1B5; Mon, 30 Mar 2020 13:13:29 +0000 (UTC) Subject: Re: [PATCH 1/3] kexec: Prevent removal of memory in use by a loaded kexec image To: James Morse 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> <9cb4ea0d-34c3-de42-4b3f-ee25a59c4835@redhat.com> <72672e2c-a57a-8df9-0cff-8035cbce7740@redhat.com> <34274b02-60ba-eb78-eacd-6dc1146ed3cd@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= mQINBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3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AtgYu1nUsPAo+NftU CxrhjHtLn4QEBpkbErnXQyMjHpIatlYGutVMS91XTQXYydCh5crMPs7hYVsvnmGHIaB9ZMfB njnuI31KBiLUks+paRkHQlFcgS2N3gkRBzH7xSZ+t7Re3jvXdXEzKBbQ+dC3lpJB0wPnyMcX FOTT3aZT7IgePkt5iC/BKBk3hqKteTnJFeVIT7EC+a6YUFg= Organization: Red Hat GmbH Message-ID: <80e4d1d7-f493-3f66-f700-86f18002d692@redhat.com> Date: Mon, 30 Mar 2020 15:13:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <34274b02-60ba-eb78-eacd-6dc1146ed3cd@arm.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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: > Adding a sentence about the way kexec load works may help, the first para= graph > would read: >=20 > | Kexec allows user-space to specify the address that the kexec image sho= uld be > | loaded to. Because this memory may be in use, 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 b= een > | removed. >=20 > Do you think thats clearer? Yes, very much. Maybe add, that the target is described by user space during kexec_load() and that user space - right now - parses /proc/iomem to find applicable system memory. > [...] >=20 >>> Load kexec: >>> | root@vm:/sys/devices/system/memory# kexec -l /root/bzImage --reuse-cm= dline >>> >> >> I assume this will trigger >> >> kexec_load -> do_kexec_load -> kimage_load_segment -> >> kimage_load_normal_segment -> kimage_alloc_page -> kimage_alloc_pages >> >> Which will just allocate a bunch of pages and mark them reserved. >> >> Now, AFAIKs, all allocations will be unmovable. So none of the kexec >> segment allocations will actually end up on your DIMM (as it is onlined >> online_movable). >> >> So, the loaded image (with its segments) from user won't be problematic >> and not get placed on your DIMM. >> >> >> Now, the problematic part is (via man kexec_load) "mem and memsz specify >> a physical address range that is the target of the copy." >> >> So the place where the image will be "assembled" at when doing the >> reboot. Understood :) >=20 > Yup. >=20 > [...] >=20 >> I wonder if we should instead make the "kexec -e" fail. It tries to >> touch random system memory. >=20 > Heh, isn't touching random system memory what kexec does?! Having a racy user interface that can trigger kernel crashes feels very wrong. We should limit the impact. >=20 > Its all described to user-space as 'System RAM'. Teaching it to probe > /sys/devices/memory/... would require a user-space change. I think we should really rename hotplugged memory on all architectures. Especially also relevant for virtio-mem/hyper-v balloon, where some pieces of (hotplugged )memory blocks are partially unavailable and should not be touched - accessing them results in unpredictable behavior (e.g., crashes or discarded writes). [...] >> Will probably need some thought. But it will actually also bail out when >> user space passes wrong physical memory addresses, instead of >> triple-faulting silently. >=20 > With this change, the reboot(LINUX_REBOOT_CMD_KEXEC), call would fail. Th= is > thing doesn't usually return, so we're likely to trigger error-handling t= hat has > never run before. >=20 > (Last time I debugged one of these, it turned out kexec had taken the net= work > interfaces down, meaning the nfsroot was no longer accessible) >=20 > How can user-space know whether kexec is going to succeed, or fail like t= his? > Any loaded kexec kernel could secretly be in this broken state. >=20 > Can user-space know what caused this to become unreliable? (without readi= ng the > kernel source) >=20 >=20 > Given kexec can be unloaded by user-space, I think its better to prevent = us > getting into the broken state, preferably giving the hint that kexec us u= sing > that memory. The user can 'kexec -u', then retry removing the memory. >=20 > I think forbidding the memory-offline is simpler for user-space to deal w= ith. I thought about this over the weekend, and I don't think it's the right approach. 1. It's racy. If memory is getting offlined/unplugged just while user space is about to trigger the kexec_load(), you end up with the very same triple-fault. 2. It's semantically wrong. kexec does not need online memory ("managed by the buddy"), but still you disallow offlining memory. I would really much rather want to see user-space choosing boot memory (e.g., renaming hotplugged memory on all architectures), and checking during "kexec -e" if the selected memory is actually "there", before trying to write to it. --=20 Thanks, David / dhildenb 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=-2.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 A4BF5C43331 for ; Mon, 30 Mar 2020 13:13:44 +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 7151220733 for ; Mon, 30 Mar 2020 13:13:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rG1F8MgL"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E/ZXW1Fk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7151220733 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.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:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4kZ2uES/JOsNvlCyoqxnRoV5trNR109re+vvfmEry+8=; b=rG1F8MgLyRNoeS oXFOx7+j4nXU4cf6YUsAdg/2IJf1IPqWE1/tSGyNelpwA5reNaVenh4g4fTa1/mz52VpKIXCwo9/n 6jS7vfMHRzTaI/YryFVlRfpI42glVKt/5V3Ctg51KmrMLqzsSDQv/3QF4yD9U+WW5ohOVJ6g49Nko yjXlMXmz6HrTNDtex830nAWCV+hAmaciK6jSqA8Mw7XPl/bI28JrS1Gqv7DavMfVGy4TW++ZlB3sQ /dSC52J0aYJtY11W/+waLsmuq2yXbe6CtTq2ObZMMwAlMJP51OKEExk+dk5W/F6wW79OClSOVS5z1 lBH9CtiJrX6VlRNfYLEg==; 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 1jIuEX-0003JH-9Q; Mon, 30 Mar 2020 13:13:41 +0000 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jIuET-0003HL-JH for linux-arm-kernel@lists.infradead.org; Mon, 30 Mar 2020 13:13:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585574016; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Ao3zXk94r5n1r1NdUT1EgWM2jGWvojEWgL79T2zxRjI=; b=E/ZXW1Fkio6gNWffAODkgmahBc7j5hiY7NQNPSMTZ4l7/lcSmnscllcO7DlQyX07tOVmRw 4ex16xCfX2oYhA0UmzswGeekSnqoGUpgbDhUpjNT3b5vosvyrksXm12k2BBRWhca5q2fyT Zxdz64kCBgqPaICcpIiAXWftLwEOTgU= 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-76-cDskFl0hPaKRYJuBxlagJA-1; Mon, 30 Mar 2020 09:13:33 -0400 X-MC-Unique: cDskFl0hPaKRYJuBxlagJA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EFD1107ACCD; Mon, 30 Mar 2020 13:13:31 +0000 (UTC) Received: from [10.36.113.227] (ovpn-113-227.ams2.redhat.com [10.36.113.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C9295C1B5; Mon, 30 Mar 2020 13:13:29 +0000 (UTC) Subject: Re: [PATCH 1/3] kexec: Prevent removal of memory in use by a loaded kexec image To: James Morse References: <20200326180730.4754-1-james.morse@arm.com> <20200326180730.4754-2-james.morse@arm.com> <321e6bf7-e898-7701-dd60-6c25237ff9cd@redhat.com> <9cb4ea0d-34c3-de42-4b3f-ee25a59c4835@redhat.com> <72672e2c-a57a-8df9-0cff-8035cbce7740@redhat.com> <34274b02-60ba-eb78-eacd-6dc1146ed3cd@arm.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= mQINBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRw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nFxWE9pn4t H5QIFk7Ip8TKr5k3fXVWk4lnUi9MTF/5L/mWqdyIO1s7cjharQCstfWCzWrVeVctpVoDfJWp 4LwTuQ5yEM2KcPeElLg5fR7WB2zH97oI6/Ko2DlovmfQqXh9xWozQt0iGy5tWzh6I0JrlcxJ ileZWLccC4XKD1037Hy2FLAjzfoWgwBLA6ULu0exOOdIa58H4PsXtkFPrUF980EEibUp0zFz GotRVekFAceUaRvAj7dh76cToeZkfsjAvBVb4COXuhgX6N4pofgNkW2AtgYu1nUsPAo+NftU CxrhjHtLn4QEBpkbErnXQyMjHpIatlYGutVMS91XTQXYydCh5crMPs7hYVsvnmGHIaB9ZMfB njnuI31KBiLUks+paRkHQlFcgS2N3gkRBzH7xSZ+t7Re3jvXdXEzKBbQ+dC3lpJB0wPnyMcX FOTT3aZT7IgePkt5iC/BKBk3hqKteTnJFeVIT7EC+a6YUFg= Organization: Red Hat GmbH Message-ID: <80e4d1d7-f493-3f66-f700-86f18002d692@redhat.com> Date: Mon, 30 Mar 2020 15:13:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <34274b02-60ba-eb78-eacd-6dc1146ed3cd@arm.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200330_061337_709830_F2786EE7 X-CRM114-Status: GOOD ( 23.84 ) 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: Anshuman Khandual , Catalin Marinas , Bhupesh Sharma , kexec@lists.infradead.org, linux-mm@kvack.org, Eric Biederman , Andrew Morton , Will Deacon , linux-arm-kernel@lists.infradead.org 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 > Adding a sentence about the way kexec load works may help, the first paragraph > would read: > > | Kexec allows user-space to specify the address that the kexec image should be > | loaded to. Because this memory may be in use, 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. > > Do you think thats clearer? Yes, very much. Maybe add, that the target is described by user space during kexec_load() and that user space - right now - parses /proc/iomem to find applicable system memory. > [...] > >>> Load kexec: >>> | root@vm:/sys/devices/system/memory# kexec -l /root/bzImage --reuse-cmdline >>> >> >> I assume this will trigger >> >> kexec_load -> do_kexec_load -> kimage_load_segment -> >> kimage_load_normal_segment -> kimage_alloc_page -> kimage_alloc_pages >> >> Which will just allocate a bunch of pages and mark them reserved. >> >> Now, AFAIKs, all allocations will be unmovable. So none of the kexec >> segment allocations will actually end up on your DIMM (as it is onlined >> online_movable). >> >> So, the loaded image (with its segments) from user won't be problematic >> and not get placed on your DIMM. >> >> >> Now, the problematic part is (via man kexec_load) "mem and memsz specify >> a physical address range that is the target of the copy." >> >> So the place where the image will be "assembled" at when doing the >> reboot. Understood :) > > Yup. > > [...] > >> I wonder if we should instead make the "kexec -e" fail. It tries to >> touch random system memory. > > Heh, isn't touching random system memory what kexec does?! Having a racy user interface that can trigger kernel crashes feels very wrong. We should limit the impact. > > Its all described to user-space as 'System RAM'. Teaching it to probe > /sys/devices/memory/... would require a user-space change. I think we should really rename hotplugged memory on all architectures. Especially also relevant for virtio-mem/hyper-v balloon, where some pieces of (hotplugged )memory blocks are partially unavailable and should not be touched - accessing them results in unpredictable behavior (e.g., crashes or discarded writes). [...] >> Will probably need some thought. But it will actually also bail out when >> user space passes wrong physical memory addresses, instead of >> triple-faulting silently. > > With this change, the reboot(LINUX_REBOOT_CMD_KEXEC), call would fail. This > thing doesn't usually return, so we're likely to trigger error-handling that has > never run before. > > (Last time I debugged one of these, it turned out kexec had taken the network > interfaces down, meaning the nfsroot was no longer accessible) > > How can user-space know whether kexec is going to succeed, or fail like this? > Any loaded kexec kernel could secretly be in this broken state. > > Can user-space know what caused this to become unreliable? (without reading the > kernel source) > > > Given kexec can be unloaded by user-space, I think its better to prevent us > getting into the broken state, preferably giving the hint that kexec us using > that memory. The user can 'kexec -u', then retry removing the memory. > > I think forbidding the memory-offline is simpler for user-space to deal with. I thought about this over the weekend, and I don't think it's the right approach. 1. It's racy. If memory is getting offlined/unplugged just while user space is about to trigger the kexec_load(), you end up with the very same triple-fault. 2. It's semantically wrong. kexec does not need online memory ("managed by the buddy"), but still you disallow offlining memory. I would really much rather want to see user-space choosing boot memory (e.g., renaming hotplugged memory on all architectures), and checking during "kexec -e" if the selected memory is actually "there", before trying to write to it. -- Thanks, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel