Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1291228iol; Fri, 10 Jun 2022 04:36:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0m6CrFmf+YsginIQ1rvGRcWxW7qRpC/pnWD3LS9USJ5ghuckpJMpGGcCCO9NI0Md7eRN9 X-Received: by 2002:a17:907:3f9f:b0:6fe:f9e2:9c6a with SMTP id hr31-20020a1709073f9f00b006fef9e29c6amr41667303ejc.479.1654861014720; Fri, 10 Jun 2022 04:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654861014; cv=none; d=google.com; s=arc-20160816; b=L/miI9xilzXbvvnDk4iNPRlqUmy990xb8jTr0TLfFpdpeohPIRrzfNVnHzLn32jyLf g5m+dc3b0UAjQng86FEQQhu0kKsiSbvInbSR4+RtnQIDR7QH+9qf9rycn5tr1UwYQ//j PtAA8HlL8yyd3LV3NiYjZmMuXfpj9mHl5JBr4CVyGMNACA8I1O71lpkyXIy375iC+brJ fOipIuH6vdtNuZH3YfAAEYJyDuIK4K55OORC93zs8QKOqo6lBejk7ns10Tu4qd0ylwx4 zgexAFuR3wPRSYhTOplIoeQq9gotTvWOu0qiJDCsBrZESewCMmJ9Ty/KsIRP6RhvZnQ6 25WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=k4jTrgfFBUvnxNdry6oYgNWE36jTSYcrwteqssJBu/g=; b=k9sGqbHwYY11b/CbOEDxwdiWpDy328euUh0PcJioIR/0Z9uqe2FxjSIAbcx16mKTac IPuSSGA8r9kavdicWrWsMRqbctU/jT+wjsu5eeCzwNoVMQviNGGi7EM2zOFdkSQFQroM 8/DfGvhD5zdxLg0qtT1KRG2DIjhP8Fn3IGTAsDjyZmQDRXsBH4vd4kKFrajZV95Rjl/Y C2OrVtjmbKT7UP6mK+qpzmfL3NlJRIdaCEiJ2n3i/P6JkY1T6ylFf7NJrVV8EJrq/T2p RJPmJEZw4BAUBBovn19Yldj5WE1DQYwuaVneCPex9JqjM9q77kZtwUZfp8JPh//wacPX oa9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OdW49OZ2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f29-20020a170906739d00b0071210178d15si3752567ejl.852.2022.06.10.04.36.28; Fri, 10 Jun 2022 04:36:54 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OdW49OZ2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245428AbiFJLZT (ORCPT + 99 others); Fri, 10 Jun 2022 07:25:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233916AbiFJLZR (ORCPT ); Fri, 10 Jun 2022 07:25:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3909EED7A2; Fri, 10 Jun 2022 04:25:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B879EB832C7; Fri, 10 Jun 2022 11:25:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C876C34114; Fri, 10 Jun 2022 11:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654860312; bh=R7E/rhnNrACRko2rS5mkC65LV2AS1sbDF48bNArKqCg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=OdW49OZ2G0DH43aev+ICAtbsWWbHFStsHOeouI2lqbtIyLGMJGpYKEBSBYc6C2gDU 4FOes5PXQLmq3w9wvl5ThMGVeixrpPPc0D/MbI8GlyBCn8W9UPhyyaLbIPLt39Uixj W83f7yjjDrQ2QbLxD64P00x5W+9bMoOHgzskdAnsDhGUTR9z3KD/lSA++1X2Hv7U/l Hlm5rn2MmmpUMTCSAiZVuN9fu/g6Q9ZxVl7lAWVoSkPtRqGXxxnCivuuk8cRSIQNTf 0XsKWPW+A8tLwC2X71bA2wXl7vUzqj6GkeStCkQxrcchfH/UkeiM9zD3v4ghjPTZwG 8TfdoW95quHUg== Received: by mail-oi1-f174.google.com with SMTP id bl34so3672142oib.1; Fri, 10 Jun 2022 04:25:12 -0700 (PDT) X-Gm-Message-State: AOAM5327BK6Ug5tAY21OYaI/V+vtEeuTq60Dh/SsT4ffz7vzo+qx7E5i ltyrrtWFFNnef92J+Rl5vBWkTIHX7mGka3yDenk= X-Received: by 2002:a05:6871:5c8:b0:f3:3c1c:126f with SMTP id v8-20020a05687105c800b000f33c1c126fmr4439313oan.126.1654860300884; Fri, 10 Jun 2022 04:25:00 -0700 (PDT) MIME-Version: 1.0 References: <20220607093805.1354256-1-mawupeng1@huawei.com> In-Reply-To: From: Ard Biesheuvel Date: Fri, 10 Jun 2022 13:24:48 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 0/6] introduce mirrored memory support for arm64 To: Wupeng Ma , Andrew Morton , Mike Rapoport Cc: Jonathan Corbet , Will Deacon , Catalin Marinas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Paul E. McKenney" , Kees Cook , songmuchun@bytedance.com, Randy Dunlap , damien.lemoal@opensource.wdc.com, Stephen Boyd , Wei Liu , Robin Murphy , David Hildenbrand , Anshuman Khandual , Zhen Lei , Kefeng Wang , gpiccoli@igalia.com, Huacai Chen , Geert Uytterhoeven , chenzhou10@huawei.com, vijayb@linux.microsoft.com, Linux Doc Mailing List , Linux Kernel Mailing List , Linux ARM , linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Fri, 10 Jun 2022 at 13:23, Ard Biesheuvel wrote: > > On Tue, 7 Jun 2022 at 11:16, 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 > > > > Memory mirroring is a technique used to separate memory into two separate > > channels, usually on a memory device, like a server. In memory mirroring, > > one channel is copied to another to create redundancy. This method makes > > input/output (I/O) registers and memory appear with more than one address > > range because the same physical byte is accessible at more than one > > address. Using memory mirroring, higher memory reliability and a higher > > level of memory consolidation are possible. > > > > These EFI memory regions have various attributes, and the "mirrored" > > attribute is one of them. The physical memory region whose descriptors > > in EFI memory map has EFI_MEMORY_MORE_RELIABLE attribute (bit: 16) are > > mirrored. The address range mirroring feature of the kernel arranges such > > mirrored regions into normal zones and other regions into movable zones. > > > > Arm64 can support this too. So mirrored memory support is added to support > > arm64. > > > > The main purpose of this patch set is to introduce mirrored support for > > arm64 and we have already fixed the problems we had which is shown in > > patch #5 to patch #8 and try to bring total isolation in patch #9 which > > will disable mirror feature if kernelcore is not specified. > > > > In order to test this support in arm64: > > - patch this patch set > > - add kernelcore=mirror in kernel parameter > > - start you kernel > > > > Patch #1-#2 introduce mirrored memory support form arm64. > > Patch #3-#5 fix some bugs for arm64 if memory reliable is enabled. > > Patch #6 disable mirror feature if kernelcore is not specified. > > > > Thanks to Ard Biesheuvel's hard work [1], now kernel will perfer mirrored > > memory if kaslr is enabled. > > > > [1] https://lore.kernel.org/linux-arm-kernel/CAMj1kXEPVEzMgOM4+Yj6PxHA-jFuDOAUdDJSiSxy_XaP4P7LSw@mail.gmail.com/T/ > > > > Changelog since v2: > > - remove efi_fake_mem support > > - remove Commit ("remove some redundant code in ia64 efi_init") since > > efi_print_memmap() is not public > > - add mirror flag back on initrd memory > > > > Changelog since v1: > > - update changelog in cover letter > > - use PHYS_PFN in patch #7 > > > > Ma Wupeng (6): > > 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: Add mirror flag back on initrd memory > > efi: Disable mirror feature if kernelcore is not specified > > > > I have tested these changes on QEMU/arm64 with the patch below, and > things seem to work as expected. We have some minor issues to work out > but the general shape of this code is good. > > As for the mm/ changes: does anyone mind if I take those through the > EFI tree as well? I don't think the EFI and -mm changes depend on each > other, so they can go into -mm separately as well. diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index f515394cce6e..1d4dd8aca3e6 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -136,6 +136,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, enum efi_secureboot_mode secure_boot; struct screen_info *si; efi_properties_table_t *prop_tbl; + const efi_dxe_services_table_t *efi_dxe_table; efi_system_table = sys_table_arg; @@ -161,6 +162,20 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, goto fail; } + efi_dxe_table = get_efi_config_table(EFI_DXE_SERVICES_TABLE_GUID); + if (efi_dxe_table) { + efi_physical_addr_t pa = 0x60000000; + efi_gcd_memory_space_desc_t desc; + + status = efi_dxe_call(get_memory_space_descriptor, pa, &desc); + if (status != EFI_SUCCESS) + efi_err("Failed to get memory space descriptor: %lx\n", status); + status = efi_dxe_call(set_memory_space_capabilities, pa, SZ_1G, + desc.capabilities | EFI_MEMORY_MORE_RELIABLE); + if (status != EFI_SUCCESS) + efi_err("Failed to set memory space capabilities: %lx\n", status); + } + /* * Get the command line from EFI, using the LOADED_IMAGE * protocol. We are going to copy the command line into the diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index b0ae0a454404..bf11d85bf9b4 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -378,7 +378,8 @@ union efi_dxe_services_table { void *schedule; void *trust; void *process_firmware_volume; - void *set_memory_space_capabilities; + efi_status_t (__efiapi *set_memory_space_capabilities)(efi_physical_addr_t, + u64, u64); }; struct { efi_table_hdr_t hdr;