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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F2A6C433EF for ; Fri, 10 Jun 2022 11:25:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A5458D008F; Fri, 10 Jun 2022 07:25:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 055A26B0140; Fri, 10 Jun 2022 07:25:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E609E8D008F; Fri, 10 Jun 2022 07:25:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D5DC36B013F for ; Fri, 10 Jun 2022 07:25:18 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id B0EF560301 for ; Fri, 10 Jun 2022 11:25:18 +0000 (UTC) X-FDA: 79562095116.03.FCD342C Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf15.hostedemail.com (Postfix) with ESMTP id 9852AA0063 for ; Fri, 10 Jun 2022 11:25:17 +0000 (UTC) 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 sin.source.kernel.org (Postfix) with ESMTPS id A236ACE3479 for ; Fri, 10 Jun 2022 11:25:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7E7EC3411E for ; 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-f175.google.com with SMTP id y69so21405367oia.7 for ; Fri, 10 Jun 2022 04:25:12 -0700 (PDT) X-Gm-Message-State: AOAM531iduYkW0uh5ykXKhFOQX0gCXghDi9xhs47Z59HyeWSp9FERG5c asg+3f5oUJx4KIW09GtxxFjInbcXUbR5qsIn7bA= X-Google-Smtp-Source: ABdhPJxchFb1YBSq+ODryfDT61Kd03pOAps2R21snltVHICUuIHqUgkA3se7XxGAoa7fI3/uaYqtBouurO7FziMDMm8= 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" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654860318; a=rsa-sha256; cv=none; b=U0R+KQYrP36TaFcL6LJjhNSNSXjBPM1S/GclMXnlqV4ZTIJqALnXDwwdhr1ESrdl+k7QqK icG2Wy/hJO+gqzbY9NMJxEeylXURZly5uCIuMcS4M+MjQsonIwmGQ7vURko1oseKgbzksr mq71MihLGtJxMdHd9iSiVV6UlxpIBrE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OdW49OZ2; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of ardb@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=ardb@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654860318; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=k4jTrgfFBUvnxNdry6oYgNWE36jTSYcrwteqssJBu/g=; b=yECrGMzeE74dmqbyMnlPjx9+uDtiHZBI6W2CWAzQ7r0TsFtc8IwTQ84PyWYipdIpOQbziu icDLpGuSqfh/eaui9r/cFTM1syzpd+3hPtOfH0l2u3BKMPiHHW4Cff6zqA7aznH1ma9s9J mhIANeX3fFiEeBEPN6cL0YvlB4/hktw= X-Stat-Signature: wwy9qrrymttnnhgxnx8pjrfku33eemd7 X-Rspamd-Queue-Id: 9852AA0063 X-Rspam-User: X-Rspamd-Server: rspam10 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OdW49OZ2; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of ardb@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=ardb@kernel.org X-HE-Tag: 1654860317-156227 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: 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;