Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp368029pxb; Tue, 29 Mar 2022 05:17:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI8oqowSd0tyqkfnxeqEss1jwL7IPa2tic/kmTWKzrW2lq0XqZsVwRlDblMou3skjZWEUc X-Received: by 2002:a05:6e02:198c:b0:2c8:4e15:7cb9 with SMTP id g12-20020a056e02198c00b002c84e157cb9mr8051887ilf.24.1648556277319; Tue, 29 Mar 2022 05:17:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648556277; cv=none; d=google.com; s=arc-20160816; b=TIpR4pNtOQmb9Jj3uHw6GRd/mmdcAPrw6A5i6m1eLyHpG/WJFugV+WxWoHgA11lPhH d+6Hh1lS3U6uQEoLr+gS/trnRCkoTiQA5JzI2TqYcu+RyL5aQygD5fmLNSmlWVOcRa+1 b8juSAqTyQ0h+6iRfmuXys0KkeNegNGFyGyK4ll7ExR19dUxsFfTnh0pLftbLmi3Ie2E CvVw+OVYmvTXB9PU5Zz3loCng82XKfWnOoQKzTeqVJUJVe7hicy/XGrHHrvkf4Qp7fPn 3aWGjGdZJ9jo+VNv4HQYk/Fqo0Kfhqlgza7Slouqi2hmCB1/Hy+dSNi7xlUufFKTRFN0 1+Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=KYw+QO7xFGI1zXEXrr/8tY/VxkaDcTV5+D2LocyR3Zk=; b=tfsUFIe8M3c3M011GndnYkKjlXz8pyvmwSwCwdsgJFNGFz65DKw9uDzsE4upzGkwA7 g+CTsacYITE56TdXvHPUVbXMwRLgdWOMiMjgx98tJd9jJws6kf6IdwhL/sjsbXJsek4d qZWgvdkFaSIH3XU1b+AnnoF/Fk3z7DoISKm1dGDsFnr9fg0RQjOMUicMSueHlhILmGA9 kv7WiZS12Nxan9B7UHNC5OyB0zM7qxA6z50SYGofy/nutrIoG25b+WbyiXx6OmPvZ59+ YbdYoiS94CbELcabJUmkGcp9176IqEeT9wNukL4VsgZCBMgRwWK4/n0eLGhTG5h3TM0R dMgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a023b05000000b003236a8ca6absi6927312jaa.73.2022.03.29.05.17.42; Tue, 29 Mar 2022 05:17:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235519AbiC2LF2 (ORCPT + 99 others); Tue, 29 Mar 2022 07:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiC2LFZ (ORCPT ); Tue, 29 Mar 2022 07:05:25 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33F071A82E; Tue, 29 Mar 2022 04:03:39 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KSRWF10D9z1GD1m; Tue, 29 Mar 2022 19:03:21 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 29 Mar 2022 19:03:37 +0800 Received: from [10.174.178.120] (10.174.178.120) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.21; Tue, 29 Mar 2022 19:03:35 +0800 Message-ID: <4136ec1c-51a9-3874-9bf3-c81cd88e868a@huawei.com> Date: Tue, 29 Mar 2022 19:03:35 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH 0/9] introduce mirrored memory support for arm64 To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20220326064632.131637-1-mawupeng1@huawei.com> From: mawupeng In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.120] X-ClientProxiedBy: dggeme706-chm.china.huawei.com (10.1.199.102) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/3/29 16:26, Ard Biesheuvel 写道: > On Sat, 26 Mar 2022 at 07:27, Wupeng Ma wrote: >> >> From: Ma Wupeng >> >> Commit b05b9f5f9dcf ("x86, mirror: x86 enabling - find mirrored memory ranges") >> introduced mirrored memory support for x86. This support rely on UEFI to >> report mirrored memory address ranges. See UEFI 2.5 spec pages 157-158: >> >> http://www.uefi.org/sites/default/files/resources/UEFI%202_5.pdf >> >> Arm64 can support this too. So mirrored memory support is added to support >> arm64. >> > > What is the point of this if the kernel itself is not loaded in > EFI_MORE_RELIABLE memory? On x86, this is handled by the decompressor, > but that does not exist on arm64. Do you mean this is x86, commit c05cd79750fb ("x86/boot/KASLR: Prefer mirrored memory regions for the kernel physical address"). This scenario is not considered. > > The problem here is that UEFI defines this as a memory *attribute* > rather than a memory *type*, which means you cannot allocate > EFI_MORE_RELIABLE memory easily: you have to iterate over the memory > map and look for regions with the desired attribute, and allocate > those pages explicitly. I'd prefer to implement this in the > bootloader, and only add minimal logic to the stub to respect the > placement of the kernel by the loader if the loader signals it to do > so (there are other reasons for this - I will cc you on a patch > shortly that implements this) Thanks for your incoming patch. > > This also means that the fake_mem stuff is not going to work: the > memory map observed by the stub comes straight from the firmware, and > if the stub needs to be involved in placing (or respecting the > placement by the loader of) the kernel image, it needs to observe > those EFI_MORE_RELIABLE regions too. If you don't have access to a > machine that actually exposes EFI_MORE_RELIABLE memory, I suggest you > prototype it in QEMU/edk2 instead. You are right fake_mem stuff is not going to work. But, efi_fake_mem is used for testing mirrored features and will not be used in production environment. This test features can fake memory's attribute values. The reason why efi_fake_mem support is put first is that memory's attribute is reported by BIOS which is hard to simulate. With this support, any arm64 machines with efi support can easily test mirrored features. > > In fact, we have been trying very hard not to touch the firmware > provided memory map at all on ARM, rather than use it as a scratchpad > for all kinds of annotations. This means, for instance, that kexec is > idempotent - the next kernel should not be affected by modifications > to the memory map applied by the previous kernel. Yes, you're absolutely right. Efi_fake_mem is incompatible with kdump which will use kexec. But we can remove specify cmdline(efi_fake_mem=xx) by modofing /etc/sysconfig/kdump. Efi_fake_mem is only used for testing and will not be used in production environment. > > In summary, implementing kernelcore=mirror for arm64 is fine with me, > but there are some issues we need to address first. > Can you be clear what the issues are? The main purpose of this patchset is to introduce mirrored support for arm64 and we have already fixed the problems we had which is shown in patch #5 to patch #7 and try to bring total isolation in patch #8 which will disable mirror feature if kernelcore is not specified. Thanks for reviewing. > > > >> Patch #1-#2 introduce efi_fake_mem support for arm64. >> Patch #3-#4 introduce mirrored memory support form arm64. >> Patch #5-#7 fix some bugs for arm64 if memory reliable is enabled. >> Patch #8 disable mirror feature if kernelcore is not specified. >> Patch #9 remove some redundant code in ia64 efi_init. >> >> Ma Wupeng (9): >> efi: Make efi_print_memmap() public >> arm64: efi: Add fake memory support >> efi: Make efi_find_mirror() public >> arm64/mirror: arm64 enabling - find mirrored memory ranges >> mm: Ratelimited mirrored memory related warning messages >> mm: Demote warning message in vmemmap_verify() to debug level >> mm: Calc the right pfn if page size is not 4K >> efi: Disable mirror feature if kernelcore is not specified >> ia64/efi: Code simplification in efi_init >> >> .../admin-guide/kernel-parameters.txt | 4 +- >> arch/arm64/kernel/setup.c | 3 ++ >> arch/ia64/kernel/efi.c | 37 +----------------- >> arch/x86/include/asm/efi.h | 5 --- >> arch/x86/platform/efi/efi.c | 39 ------------------- >> drivers/firmware/efi/Kconfig | 2 +- >> drivers/firmware/efi/efi.c | 26 +++++++++++++ >> drivers/firmware/efi/memmap.c | 16 ++++++++ >> include/linux/efi.h | 4 ++ >> include/linux/mm.h | 2 + >> mm/memblock.c | 4 +- >> mm/page_alloc.c | 4 +- >> mm/sparse-vmemmap.c | 2 +- >> 13 files changed, 60 insertions(+), 88 deletions(-) >> >> -- >> 2.18.0.huawei.25 >> > .