From patchwork Fri Mar 10 09:45:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13169045 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 CA8BBC64EC4 for ; Fri, 10 Mar 2023 09:46:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 264C46B0072; Fri, 10 Mar 2023 04:46:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2149D6B0074; Fri, 10 Mar 2023 04:46:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 091428E0001; Fri, 10 Mar 2023 04:46:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EB76C6B0072 for ; Fri, 10 Mar 2023 04:46:49 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C7C551416E7 for ; Fri, 10 Mar 2023 09:46:49 +0000 (UTC) X-FDA: 80552509338.28.6ECAD23 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf19.hostedemail.com (Postfix) with ESMTP id C56CA1A000B for ; Fri, 10 Mar 2023 09:46:46 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=DK0AVNF2; spf=pass (imf19.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678441606; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KgQQy0WOaC8x36p48NSIJDImmcDBT39MIpy6PGzDwU8=; b=dscYQSMjdPFniHt7+VAVnGOqbBowvxO8o/W4ByH5O41Xu0qkc63t9e6zBZ4in1GXGcw0TO bS40N5gXXfmRKo9eMXROZdaQh+aUjfaX1S5xpdhIeeZcL4CBuNAPyVL70dg1Z1hon+qDgQ kBSqlHTwnlmtDDMHwyiSDnlS0sIMJYc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=DK0AVNF2; spf=pass (imf19.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678441606; a=rsa-sha256; cv=none; b=DyxzcjWVP0eA1YiN8tpKySn5BKSOq+M5WGnuZTnwF4UY0j7+ks+wrfOus0ZcMMaH6BIXiO IzH9SwgpSQ3GDbhSWWeiyG0OwIq3OBcf+pYEmiB7xg9rkP3UBRBjwD09V+MUcNroR3OjN7 /B4L8hlOunRzHJhnmD5JGghLrrf0wTA= Received: by mail-wm1-f53.google.com with SMTP id j19-20020a05600c191300b003eb3e1eb0caso5556497wmq.1 for ; Fri, 10 Mar 2023 01:46:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678441605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KgQQy0WOaC8x36p48NSIJDImmcDBT39MIpy6PGzDwU8=; b=DK0AVNF24CSovjJHjfX2BnbZdKEc3SCRhmed7jkWmNWONYRQJpkIDL/dDxC8+TqV4s iPdx2usmr4K0UsSvTjdyMJmHIJpwPpBtCXOt0TWuokX7Zry9p/D+3rjrf+QNRJWTAH9d FjemEPIjcSPl6Z/IT3jQJZ+EuCULRYq4LA1+kUq2ILkogKGSgomgez1hILg2QQS3XD5g MnLjt536CUEpLSQiQqLquY6n4kpR5vSmgTKTmGbi96kMFXMKcVgHdPrFYi3R8Xkr71dD FrlWWYDKsTczd5y5BLAiMFpgQ4ohQfrZRU/KQHi3A7pE0F0Ua9QPnaql2wwabry3iuEd DTwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678441605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KgQQy0WOaC8x36p48NSIJDImmcDBT39MIpy6PGzDwU8=; b=fRYNK4Lzr9Fcw3L2oQqAvlBCp3tLLWKbLE2oanYM5w4m43CIal/k4bxZ51Vz1xaw27 +sD1WwxlUbcwvTNQ5F6R4Q+cJQPFx/WDKvmBpCILLCOw0BuZfxgT8mJC/w2KsClsQpXK vO+CFwfE4/tQOvO5dv0qTB46yebdRwA7F0RbDYdOUYoFJu9RoM7eNkOnpvQPT5gZmcYh 18VUVcrJ4HXYIghrOROBtMHNEQPqEuNjzwxiXfRqovyviOjl06bxCHpgdpfBlC7rHOoA vRgDB6LPkVifLrrHygs3r83I/6l/q+jI9nA4CE/3rFY82XIZ/NaRHMCkDocOEcWJgVH/ 064w== X-Gm-Message-State: AO0yUKV1/2ps3WBnGAWp4OLJvlt9igcTdGjz3nioCoHDZ4uJRGofvaQn pVBC54YOqcsWDwvwtz1fnGPBXw== X-Google-Smtp-Source: AK7set8b349TneToQStuc8wRqpg6p575gxaExAvpkNXCodRjWOTreYyk5UxGc9fCPDchPDs9B8XsoA== X-Received: by 2002:a05:600c:4452:b0:3eb:2de8:b739 with SMTP id v18-20020a05600c445200b003eb2de8b739mr1958858wmn.37.1678441605417; Fri, 10 Mar 2023 01:46:45 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id iz9-20020a05600c554900b003eb369abd92sm2461929wmb.2.2023.03.10.01.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 01:46:45 -0800 (PST) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Mike Rapoport , Andrew Morton , Anup Patel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti , Andrew Jones Subject: [PATCH v7 1/4] riscv: Get rid of riscv_pfn_base variable Date: Fri, 10 Mar 2023 10:45:36 +0100 Message-Id: <20230310094539.764357-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230310094539.764357-1-alexghiti@rivosinc.com> References: <20230310094539.764357-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6f9nnix7bwjbg33jc9nq4njdy6pomyu6 X-Rspamd-Queue-Id: C56CA1A000B X-HE-Tag: 1678441606-114069 X-HE-Meta: U2FsdGVkX18VwmAneZF1B2qWW8etuAq6Tgp17RFQnPXu3TRc8rxKWdmR9ReVRbbFgkeiitzrZCmHsjjBkiB/hWRDEHDK4a2SKrryJAGVw5eQbvxWx+hA4aKNKFwTHcwPEQV4whi9lEXgu759IHBryNNzvDzOOL8uCn5aPyI8PbOI2RpkcsO1YkXKjNQSZbOkAO0CvmRk893fhUqkdKklajV3n6C0+kxb3h1/c16dwgSdMZAPAEqKObhH/vf6Th4trpmtJSet9Qye/vkMa+AvcYwF5SSpxpMwpse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56eXqqRoAWF9rImDVaAKYWsQ95Jss2vvGAJT1qbu0eURkN1PE574NnKgrdmOrq28BuG5Egiw4sbfMZHGS7Po03a/zNiCyJr6TiF7a2aeGLIsQsILA+UmMaRSYeKDZ4rz/ZtaMbfNOl+wmRhIw1mjKAEK8OK/v6bAijAMTl6ZGyZnNV7heE8mn7FvKgDIg+kBQDAAskHSpxXEi1lJk/j78DS9GdKXwA46vdoY8obfa+vi9v1uZG0H60MDOUfZpa0IY4Ek2mrwog= 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: Use directly phys_ram_base instead, riscv_pfn_base is just the pfn of the address contained in phys_ram_base. Even if there is no functional change intended in this patch, actually setting phys_ram_base that early changes the behaviour of kernel_mapping_pa_to_va during the early boot: phys_ram_base used to be zero before this patch and now it is set to the physical start address of the kernel. But it does not break the conversion of a kernel physical address into a virtual address since kernel_mapping_pa_to_va should only be used on kernel physical addresses, i.e. addresses greater than the physical start address of the kernel. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones --- arch/riscv/include/asm/page.h | 3 +-- arch/riscv/mm/init.c | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 7fed7c431928..8dc686f549b6 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -91,8 +91,7 @@ typedef struct page *pgtable_t; #endif #ifdef CONFIG_MMU -extern unsigned long riscv_pfn_base; -#define ARCH_PFN_OFFSET (riscv_pfn_base) +#define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base)) #else #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) #endif /* CONFIG_MMU */ diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 478d6763a01a..225a7d2b65cc 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -271,9 +271,6 @@ static void __init setup_bootmem(void) #ifdef CONFIG_MMU struct pt_alloc_ops pt_ops __initdata; -unsigned long riscv_pfn_base __ro_after_init; -EXPORT_SYMBOL(riscv_pfn_base); - pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss; static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss; @@ -285,7 +282,6 @@ static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAG #ifdef CONFIG_XIP_KERNEL #define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&pt_ops)) -#define riscv_pfn_base (*(unsigned long *)XIP_FIXUP(&riscv_pfn_base)) #define trampoline_pg_dir ((pgd_t *)XIP_FIXUP(trampoline_pg_dir)) #define fixmap_pte ((pte_t *)XIP_FIXUP(fixmap_pte)) #define early_pg_dir ((pgd_t *)XIP_FIXUP(early_pg_dir)) @@ -985,7 +981,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) kernel_map.va_pa_offset = PAGE_OFFSET - kernel_map.phys_addr; kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr; - riscv_pfn_base = PFN_DOWN(kernel_map.phys_addr); + phys_ram_base = kernel_map.phys_addr; /* * The default maximal physical memory size is KERN_VIRT_SIZE for 32-bit From patchwork Fri Mar 10 09:45:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13169046 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 5A4B4C6FD19 for ; Fri, 10 Mar 2023 09:47:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D87DA6B0074; Fri, 10 Mar 2023 04:47:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D379C6B0075; Fri, 10 Mar 2023 04:47:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C00B38E0001; Fri, 10 Mar 2023 04:47:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AF5746B0074 for ; Fri, 10 Mar 2023 04:47:49 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 748E4ABC32 for ; Fri, 10 Mar 2023 09:47:49 +0000 (UTC) X-FDA: 80552511858.02.F2B4696 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by imf09.hostedemail.com (Postfix) with ESMTP id 800D0140007 for ; Fri, 10 Mar 2023 09:47:47 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=JUZ6MS0e; spf=pass (imf09.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678441667; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y6J6lRuGpbM7E9O7f7bljUjx0eKgcV/6jZ6mdNRRq+4=; b=RhMWomoaqMY5qEFyIfnwD9LDKcpObiz64KNLd3zf9jAkXTyQgEVAs18rWL23KyA6vu+SQk dxEmuI4fn+jUrzqp887u1WTnSRmQZsv5wt6IalF9izeJouPz9Osqosfa/LPCsYgXzE5k1S w88Xj9lBrkoZxXS6fuQsPa4zcvcNAbE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=JUZ6MS0e; spf=pass (imf09.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678441667; a=rsa-sha256; cv=none; b=MT8h+3eg/5aRjELCYdLBl9r67xRrnp6COJacv7t4N23rL/CaEVSlUloXScQTtn1c4pfIE0 ay1uNmCmDgZbG8w/iOyKIkNBCuDVtXIeexs9s/kBP5g2lpTecSuOdCok7x//IJABIcyg60 qKh7sZP34PCcEr0pga5LA/EQYv47MIE= Received: by mail-wm1-f49.google.com with SMTP id p23-20020a05600c1d9700b003ead4835046so4677118wms.0 for ; Fri, 10 Mar 2023 01:47:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678441666; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y6J6lRuGpbM7E9O7f7bljUjx0eKgcV/6jZ6mdNRRq+4=; b=JUZ6MS0ezJc5yh4n6KTD+iS0WsCulf8ihBW2NAvKNEq0/OB5Yl3u3Id3vcVGms8+Zh dy0R5ZAoYZe1+5BB4Ca7JUS88v8KD9qo3j2ZtpZ3YcD6dhav6UfqVvBndyVRy4znafUr SnyvqHVNZEfBo+F2qRp6xuk0sVwvpBO5NzGxZbWL64VKd3PuD6o4m+7enUFb65JiLMrD 5Jvj7gBmtNYyrjDHsAI5NaAPtnjzy0RkGbkThWLIaSy6KlT9qCaNhB2m3HYD5+ztqRIL fDTxQFZDR13CddYNIljUltNoKv1Caa4FNdhMJm/MCwABN/OoQJutLpcdhPMIoHPiZaL8 5CeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678441666; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y6J6lRuGpbM7E9O7f7bljUjx0eKgcV/6jZ6mdNRRq+4=; b=dgCH3urn3J6e5LK+q6LdJu8rDxuFuU1G3ir7KeeZYQlMF4tcnQAWQE5uwHbSXV+dP5 xk8hyEZifMZQRsg4Y0tWTETO7ZKWx1IikJs0oDrGFHtVKYFU1xOVVou7SBRRVVteQKt1 O1HQlJstfOxKvOel7VO75I9qEZmcbi+Oz9rkZG7RTyOlcJN2+uXjWjrK6t+hZC4PTdad gGd1hMHCOKt9yCeHZcOPdrrUISKiHO3JWbRY0858JTEqcKp+4HXSxkbuWhQzJjZ7v9CH KOU7SK4dyvBH3szDVeodIvo9UDuLnUTWn2QJciqVS6KKQCPAQobemnUToXlSZ0+n8YT2 WlxQ== X-Gm-Message-State: AO0yUKVCgE5v/TMtsyNRmGX/k8u5I81EE710bNfHEC+Bs7vuOIXDI194 0TYvabz/OFZ5Bbn6/DPfrkcyfg== X-Google-Smtp-Source: AK7set+hIKDyMZLEzQZwJrQZ4Ml18aDplEsgmJbGeNc4aX7RXiRyHxB8XeJIUJU9oYunTbo6EYqvmg== X-Received: by 2002:a05:600c:198e:b0:3eb:2f3b:4477 with SMTP id t14-20020a05600c198e00b003eb2f3b4477mr1930695wmq.28.1678441666270; Fri, 10 Mar 2023 01:47:46 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id g9-20020a7bc4c9000000b003e20970175dsm2410949wmk.32.2023.03.10.01.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 01:47:46 -0800 (PST) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Mike Rapoport , Andrew Morton , Anup Patel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH v7 2/4] mm: Introduce memblock_isolate_memory Date: Fri, 10 Mar 2023 10:45:37 +0100 Message-Id: <20230310094539.764357-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230310094539.764357-1-alexghiti@rivosinc.com> References: <20230310094539.764357-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 800D0140007 X-Stat-Signature: k84yefrf6ycdktoth9ofgxx4kbdc5apa X-HE-Tag: 1678441667-5642 X-HE-Meta: U2FsdGVkX189IjGTBTo26PyKjIw+eknccYCr8SQlWiOeFoSIsAXCqYujTcccrFalHX9jZGQII4zCrmvWI6cF5NbM7AkwgNC2XbyWO80hi0RC/rN/ViDYHg9/SUAbxBs078c2OeTA5PqkzQ+uw3FP95tkidt9y7Fy2BqwGLhuIvKgiFZ3PR+bSwVhb1iK7OIqOlSt3NnvG5TZ6S00O4R+zKAmEoZ9a4vU2cFxlURQqdXMQXMIT3nRA7hrBxWe1yyC5mV1by/Ip8d4OYAcIkUfkzIIb49ILxbA+BRFA5QoEtobfTMyyzv74xwr1xmQ27wbh9f/5EbQ58lCYn8LxMxeAYhiRM6w9SO+LV13IU/SV1RwEGxVKTR7/vJjoPLWAos2/KUL2QTT1oo9O55XxZaPwSzldPsyDfd+38+leZ2BtXawJCSh6JZhKux/YQOWQ+W3Kn01/ROy0/9nxsRFFdPYU0m5rxLGcHg/aqCU7+hYc5B6XJNWyOoURv9EGTCSU50UIdsYA89Dp3YgEqrEKDUOp0wZMUqsAozKozjYJDrBzgmbq0sUmIeDrrNDGpsjW0br6YvqNF5Xy068zpVraEIMhVibNfCj2FYWtWfRX5gqeGCQRPvH5Tu10rBy+5qclabMhV5HZZZAIXY+nepSyppXtuCg+CfeViQYQr2bUChIw+fmXia7ZLEeNoCGSTvbGmdAn+xGXhz/eNdfxPR7nA+ybfK3VI3Kws7C/LoLDxPaBCbKtEIfSzIvBzgZQ/VCW34VEMI0LWIWq/G6ZcPj4qq+3l/dX2yylZh/JqaoJxVNUJzYHzbRil1PQ/+qvUPCDBlNgaM3sQkgedLtk+pQIHOB1Lbp1fdgkEYzCFniPteBxXlEinDGJgAT5/jJXblXIQBKnb25XSXf9iBHNPdzkcvhJIDVvM8WICYHPqwHkgwPpj7Dp3zsbn59//wcnjNHZ1AI5H3Sz18EC3JktdRAwhp S5j+sEpU foZJK1GZyUSYTbQW5oyokLiERpJBqtmc2gcPHDO+GZSoq3IdIb9RuZziGFmKTX8E6utZZiMgXrN7TSUc06Brf461Uk5Oz4shY1QtRMUisV38jLEJtYD9zP9zwDUsL+PIHYkbFwlVB4nca0crKORHhfYdjCe+4Bj+08O5XH3kXPUZJXnnQn17RAnAWZkEcwUlB63joZd2gXzGtK+fkmu8C6zm8xJn8deDTLqcqktwwDmBx+qkQu8BvihGoANde4t8/tK80suh2yjLPC1w66kgbgN66kEnBqstibZgvZOx16dYCnp6FrlFmAof1wdIHcwrPs696LnZonK7E9CktH+Ze3xmr3WdYaWEV+hKbN24FeLeoTamypefwJAOEdHGmnMlHrIYE2T9dZTmXz8XvFyXKptZlt4W3Q7ancCjc1ok18vBlSAe5G0etFxLi71+f145jllKQ5VuhEst3NlSIznzUny9cyMyPIACm1SZFgAPoNLLs8uYRJwvTTn9tkt6mSILTiJYBNvedYcJF6iCMYfSvOXfKLTCVmushAk7K27uGnpGr3KPQjE1U23QXsb0wuRg0MT/T7VvI9SCAHZY= 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: This function allows to split a region in memblock.memory and will be useful when setting up the linear mapping with STRICT_KERNEL_RWX: it allows to isolate the kernel text/rodata and then avoid to map those regions with a PUD/P4D/PGD. Signed-off-by: Alexandre Ghiti --- include/linux/memblock.h | 1 + mm/memblock.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 50ad19662a32..2f7ef97c0da7 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -125,6 +125,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); +int memblock_isolate_memory(phys_addr_t base, phys_addr_t size); void memblock_free_all(void); void memblock_free(void *ptr, size_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 25fd0626a9e7..d8cf1c9eccf0 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -753,7 +753,8 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type, int idx; struct memblock_region *rgn; - *start_rgn = *end_rgn = 0; + if (start_rgn && end_rgn) + *start_rgn = *end_rgn = 0; if (!size) return 0; @@ -795,6 +796,9 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type, memblock_get_region_node(rgn), rgn->flags); } else { + if (!end_rgn || !start_rgn) + continue; + /* @rgn is fully contained, record it */ if (!*end_rgn) *start_rgn = idx; @@ -805,6 +809,22 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type, return 0; } +/** + * memblock_isolate_memory - isolate given range from memblock.memory + * @base: base of range to isolate + * @size: size of range to isolate + * + * Call memblock_isolate_range on memblock.memory to isolate the given range. + * + * Return: + * 0 on success, -errno on failure. + */ + +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size) +{ + return memblock_isolate_range(&memblock.memory, base, size, NULL, NULL); +} + static int __init_memblock memblock_remove_range(struct memblock_type *type, phys_addr_t base, phys_addr_t size) { From patchwork Fri Mar 10 09:45:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13169064 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 F33B4C6FD19 for ; Fri, 10 Mar 2023 09:48:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91A236B0072; Fri, 10 Mar 2023 04:48:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CA4B6B0074; Fri, 10 Mar 2023 04:48:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76B726B0075; Fri, 10 Mar 2023 04:48:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 666426B0072 for ; Fri, 10 Mar 2023 04:48:50 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 36F13C09E8 for ; Fri, 10 Mar 2023 09:48:50 +0000 (UTC) X-FDA: 80552514420.25.779C805 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by imf28.hostedemail.com (Postfix) with ESMTP id 6825DC0006 for ; Fri, 10 Mar 2023 09:48:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=nEDaPnA8; spf=pass (imf28.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678441728; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tGavHCNEAmB3AhZu0LKzFHubCv5xCdNflVD0ekR4UY0=; b=pSB05gCRH/YpdHCv6qEE/pDirhcxRBAXQFKfszzb4RoM3OMIBHQV35uXmPFfTkoke8Zc2M pqirhDnHqziBQaq1clRFQyLmk+lIHeP6+u/mz+FhCHNdaBDf35uYF/2Ac7TY/jftX60T7e XlqBtc9FL6oq9WNLJzIa6zr4XrVKanw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=nEDaPnA8; spf=pass (imf28.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678441728; a=rsa-sha256; cv=none; b=xfWWgEpd6eU7jUz/zogy1EGBYtMrvYQ9fL5A1g9rNPfDWEngNDtasMAel1I0paNNyroFrj 7/eoGKblAjitah2FLVlg/N3SrGsgk+t5b2qgLfsVZzCWViKRRERUDgmyzmJxnJG7tGY7QC X75S+ag4v229CHDq6BdWJqWewgJOaPE= Received: by mail-wm1-f44.google.com with SMTP id l7-20020a05600c1d0700b003eb5e6d906bso2987285wms.5 for ; Fri, 10 Mar 2023 01:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678441727; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tGavHCNEAmB3AhZu0LKzFHubCv5xCdNflVD0ekR4UY0=; b=nEDaPnA8Ty4PvBzODbwL6B2sTto11mRsb4Jzs2H7G9p6A7ZKSNrhnk3x4BOWFO5NAM I/78Se50og1itnoiMPakGj3AveG31x2j6/j/50CVZh8lwbX6MQDYxcf8yYxVJoMofzOn So11W4KjPW25NSlFIH8QkPFlfV0uo7dzOyl980DN9KkNz+cd36ioi6QDF2EBD7bd5PyU POxxiU/fHG2HLQE58X+B7ZTBTf7m1Ez0P/WNGhmIjfMIHPth9RdlR4D0u/Oxg4pQMLp3 2eK+lEAa5joep7xYw4om/Il1YLWfTzdepO6+BmZdGMIWNwLKWLRg8ZeFmMq9uBF+PfuR 4knQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678441727; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tGavHCNEAmB3AhZu0LKzFHubCv5xCdNflVD0ekR4UY0=; b=hOEcCVEtCbdpsOt0JSlReJQKRIuT0p0zuAXG5WT5ko/pKpaBI1Szg7ufchelwVxEgf 6WgxTGTzoB1esVEyp787LDAXX16rN3JUvs5/LYnHzvZZI4jGfK3HTUtpKEADku5TMwxy TSiRzK0/UXrvkKeUAYkOFrgotuCGLlOHyFRD7UwToQDV3nj/q4FnO+2Cwjn3P6w9H/jw dVdWNgjGtSzL7AvJKCLzye/EZH63h5a7xFbWl1ACXJ9VwS2dFmjBnad71q75I3t5255v 4e+dRJWYNNdFuRvoCc7bqWQf9RQ4lwlAFqXmzjIO/90QFkJNP8Gs8C2a9f/gSLQaD6rS hF5A== X-Gm-Message-State: AO0yUKVuaI0uCkXSDVtmPFL1mduiIHXtc3C7KPhCtHP/HdlprY7FUmhS 3poP7nm0YgFHewi3r9AWEOzL2Q== X-Google-Smtp-Source: AK7set+y/rX3YhT007UnAYJB6sfLfhyhEqqnKFykNxvLHTsOstaKSQULB4uzAM12oQybO0ImSo5iuQ== X-Received: by 2002:a05:600c:b8a:b0:3eb:578d:ded3 with SMTP id fl10-20020a05600c0b8a00b003eb578dded3mr1976475wmb.35.1678441727129; Fri, 10 Mar 2023 01:48:47 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id m21-20020a7bcb95000000b003dc5b59ed7asm1572826wmi.11.2023.03.10.01.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 01:48:46 -0800 (PST) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Mike Rapoport , Andrew Morton , Anup Patel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH v7 3/4] arm64: Make use of memblock_isolate_memory for the linear mapping Date: Fri, 10 Mar 2023 10:45:38 +0100 Message-Id: <20230310094539.764357-4-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230310094539.764357-1-alexghiti@rivosinc.com> References: <20230310094539.764357-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6825DC0006 X-Rspam-User: X-Stat-Signature: fnahnxy4bymw8ijwnaerrs5kn4bofpo8 X-HE-Tag: 1678441728-23034 X-HE-Meta: U2FsdGVkX1+NFhJ22Wxnylzjfw4R/utkdtSZKnp5xTYNYKW8X4vkE0rfmIeKrWhRIB+ppJQaaxwJP1MKD2HVJ0ngnRD/Pplcc3psXW+0Q+mzsBNHBb9yCJW4uu6JrcE9UfoprM+TMLxF+t9+8hVaYD53hPAIkDhYPdWyOsy6mKPyeHwG6mauMbXmjZhmljxqeG31f3E92YvuLZ3eUfsdcx8Yq4nQphMAuOCMvffTSBdp/IwZK6gdd5YbpngwOR1tOB36c+frA05/xmIzI3GAV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JhGXrKGIyaXHoqBKk06tgiMUSbYwuD804dBA+o74mx7/iO78jEDIdmXtp7sgRFMuQWdoVsncwWeYfjnquh6CvB309Q+rmG0MPGB4x/TfrPHlbmo+0c4pzxJ8a08R3X4r0xEAAYhiLwrzJ6RDOn4xtg7bACFUFuqJ1+XKtt1lV9ncp7n8OJyzW24V4nq6HI8hQXSKbsl0OF4cuCi2slPMznzcdO67QCYA= 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: In order to isolate the kernel text mapping, we used some sort of hack to isolate the kernel text range which consisted in marking this region as not mappable with memblock_mark_nomap. Simply use the newly introduced memblock_isolate_memory function which does exactly the same but does not uselessly mark the region as not mappable. Signed-off-by: Alexandre Ghiti --- arch/arm64/mm/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 6f9d8898a025..408dc852805c 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -552,7 +552,7 @@ static void __init map_mem(pgd_t *pgdp) * So temporarily mark them as NOMAP to skip mappings in * the following for-loop */ - memblock_mark_nomap(kernel_start, kernel_end - kernel_start); + memblock_isolate_memory(kernel_start, kernel_end - kernel_start); #ifdef CONFIG_KEXEC_CORE if (crash_mem_map) { @@ -568,6 +568,7 @@ static void __init map_mem(pgd_t *pgdp) for_each_mem_range(i, &start, &end) { if (start >= end) break; + /* * The linear map must allow allocation tags reading/writing * if MTE is present. Otherwise, it has the same attributes as @@ -589,7 +590,6 @@ static void __init map_mem(pgd_t *pgdp) */ __map_memblock(pgdp, kernel_start, kernel_end, PAGE_KERNEL, NO_CONT_MAPPINGS); - memblock_clear_nomap(kernel_start, kernel_end - kernel_start); /* * Use page-level mappings here so that we can shrink the region From patchwork Fri Mar 10 09:45:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13169065 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 503ECC6FD19 for ; Fri, 10 Mar 2023 09:49:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D12106B0074; Fri, 10 Mar 2023 04:49:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC2108E0001; Fri, 10 Mar 2023 04:49:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B89E26B0078; Fri, 10 Mar 2023 04:49:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A9C8E6B0074 for ; Fri, 10 Mar 2023 04:49:51 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 74A2C80953 for ; Fri, 10 Mar 2023 09:49:51 +0000 (UTC) X-FDA: 80552516982.19.C39AC20 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by imf20.hostedemail.com (Postfix) with ESMTP id 944251C001D for ; Fri, 10 Mar 2023 09:49:49 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b="REcz0/NG"; spf=pass (imf20.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678441789; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HA1xGrUXWy21CUhjf+7eNgybjNNpOnIGNYQsit2KPGw=; b=OOEC4CEiEUifRjh5gEfUL2Q3JhPsrR4d3XkH+qKTOV5vBWPe8+U//tSW0ihnwLmraehaw0 GP0Mhl+AXXbtQ0LGgMGG+uQnH10JHMo4BV4DhADJLXe7ldG8oM5EXCS7PqWCXsgE/yfvMC gzApCHQvzdEmHXMU9yu+TaygrwIXGMU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b="REcz0/NG"; spf=pass (imf20.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678441789; a=rsa-sha256; cv=none; b=rUo+4LH6kHjnxs4Cu/B+1I+Aw6s1v6zpeKLhWH1SozyqON918QzkKYq6Dov7hx3gxmKzvn nD2ZjwIMbnMXYm0T23oGL4Fz+pmLvLptFG36VdqyKNkp1hNDcZa7y//ar11bn3mHGnRaVH IME6Jgddx0JF4PLTtMLT2a8YWTaM3SQ= Received: by mail-wr1-f50.google.com with SMTP id t15so4461992wrz.7 for ; Fri, 10 Mar 2023 01:49:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678441788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HA1xGrUXWy21CUhjf+7eNgybjNNpOnIGNYQsit2KPGw=; b=REcz0/NGalsvL8YM5VfJHGHT+5Zx9APaiOS7xrZg8vWiQvcinmscsaMLtiXL7so4g4 41M5LnQ2wVaXuUl7sADBqjFOMycg8WFYosksCMrnpc5qWRhxzHgeLLpV/03M+KC8kySS 8lN49Sh4azp4adigJ06tqmHfix+oQUOTa7NKgV/8PfSZvFpDmmAU3T/8w3VjOJuIwRiT Xj2IHrW/U++aBXMB8awyytbIHjvJWW3jQCzeGF4aCAtzfxvlyWSTwBOGN9PFGet2iJY0 VMETw28kNRWzYTA48sQoBXr75q3gCuVRXpvBKfX5dzJbm/a/31uCTNfAl3rk4YehFWUU Jnuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678441788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HA1xGrUXWy21CUhjf+7eNgybjNNpOnIGNYQsit2KPGw=; b=02u1FD1F1FcvBmDTHlXb6rWxrZI6W5YVToaLS3N0nWM695JlCJKyQvBPmKnB0zG8dp 97sZVJAkWIF7B7Tmv82AQG2c+FFdgQurn3jYHCiHzgml9PAHpbIc2s/ETwDoh3qMDdHb pHGkJg2nCks6On9qJ1ymCGb5ZTILHQNGgR56Q0V2oRvaHu1IKj3mERVNHNXq9sWwv1sy wj3BLRY33tZWGWHRlW+gWUYgm/f5Dg/I8UwPk0c1XawgVQ2iGdGhZmv4pb+QYCG3J8t0 poKqQ2/fYgPk/7+IIRz4gDUS9Dfxa4y3PtTYyECbsa1mFoppw8rCTggEMqeTURXTGknM 0Atw== X-Gm-Message-State: AO0yUKVUQC7j0Zxq0rU0yNCixBE2u/1kBocGS0vun1Hb+Ipl9CHvn6ba xXv9mrbC56yFd4qPMw2rTsTKNQ== X-Google-Smtp-Source: AK7set9qtXMQ7M9i+VtP1dUiHLDOFEZSoleSlj7nJmTbrV/EejA7x32N39iwEV5LcEDhXaajfBMrVA== X-Received: by 2002:adf:dd87:0:b0:2c5:4c5e:412b with SMTP id x7-20020adfdd87000000b002c54c5e412bmr852346wrl.23.1678441788090; Fri, 10 Mar 2023 01:49:48 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id n22-20020a7bc5d6000000b003eaf666cbe0sm1616174wmk.27.2023.03.10.01.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 01:49:47 -0800 (PST) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Mike Rapoport , Andrew Morton , Anup Patel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti , Rob Herring , Andrew Jones Subject: [PATCH v7 4/4] riscv: Use PUD/P4D/PGD pages for the linear mapping Date: Fri, 10 Mar 2023 10:45:39 +0100 Message-Id: <20230310094539.764357-5-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230310094539.764357-1-alexghiti@rivosinc.com> References: <20230310094539.764357-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 944251C001D X-Stat-Signature: gx7zi6mkompscdsddoecapss6sht88rs X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678441789-944859 X-HE-Meta: U2FsdGVkX1+5FP2Y1Mk+ZqgpvD5W5Hc7vs607+mqECFrBHHz5lxyuMLxG1c8jdgg7Eunl82YtYxwqe7yG2yRXkAes2Pwg4pYYYQaj+bqf52BjrQcRtuAGyMoabDufLmzhbK6R89X/hTp50cdtqQM8yJjuUtupWpqZJPhwe1mdO6MLEYwRCLpH0I+LuHZElkQKmvA3w0fw0YX2OWj4Xea25sQ0PF3Hu6TbLFz2LtPtTM8wbShwLyoNw1T/uLSnzTnkwtekD5N24wdEBkReH4baNa7+M+UTgSPdS18Wyz1VCdEcXUZLyz9dcKGfdFT+bCDPBktW5vpg2VtaCkpDJ3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g/Yk4kiKiHawBfgnJUqXu9X1fnHTznPIJf0Bgm0NOQ13vNwBc2zzKQ7JYDOuId5bFYB1US1zY3t78SfiQTB/rYHfbpJc1ycHjnjOAivRmEPfZP2/zbp4W3ABIHuqop3ZepXWn1NXJLXVKUufjMy0fMz8qTw3s5+VuLyQvMX4gGKDC2n4vGbmqTg00n7pwYYRkfAnz1yqGZTBVMteBRuRlqdoZLXEi55ffqVIpg== 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: During the early page table creation, we used to set the mapping for PAGE_OFFSET to the kernel load address: but the kernel load address is always offseted by PMD_SIZE which makes it impossible to use PUD/P4D/PGD pages as this physical address is not aligned on PUD/P4D/PGD size (whereas PAGE_OFFSET is). But actually we don't have to establish this mapping (ie set va_pa_offset) that early in the boot process because: - first, setup_vm installs a temporary kernel mapping and among other things, discovers the system memory, - then, setup_vm_final creates the final kernel mapping and takes advantage of the discovered system memory to create the linear mapping. During the first phase, we don't know the start of the system memory and then until the second phase is finished, we can't use the linear mapping at all and phys_to_virt/virt_to_phys translations must not be used because it would result in a different translation from the 'real' one once the final mapping is installed. So here we simply delay the initialization of va_pa_offset to after the system memory discovery. But to make sure noone uses the linear mapping before, we add some guard in the DEBUG_VIRTUAL config. Finally we can use PUD/P4D/PGD hugepages when possible, which will result in a better TLB utilization. Note that we rely on the firmware to protect itself using PMP. Signed-off-by: Alexandre Ghiti Acked-by: Rob Herring # DT bits Reviewed-by: Andrew Jones --- arch/riscv/include/asm/page.h | 16 ++++++++++++++++ arch/riscv/mm/init.c | 35 +++++++++++++++++++++++++++++------ arch/riscv/mm/physaddr.c | 16 ++++++++++++++++ drivers/of/fdt.c | 11 ++++++----- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 8dc686f549b6..ea1a0e237211 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -90,6 +90,14 @@ typedef struct page *pgtable_t; #define PTE_FMT "%08lx" #endif +#ifdef CONFIG_64BIT +/* + * We override this value as its generic definition uses __pa too early in + * the boot process (before kernel_map.va_pa_offset is set). + */ +#define MIN_MEMBLOCK_ADDR 0 +#endif + #ifdef CONFIG_MMU #define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base)) #else @@ -121,7 +129,11 @@ extern phys_addr_t phys_ram_base; #define is_linear_mapping(x) \ ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE)) +#ifndef CONFIG_DEBUG_VIRTUAL #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_map.va_pa_offset)) +#else +void *linear_mapping_pa_to_va(unsigned long x); +#endif #define kernel_mapping_pa_to_va(y) ({ \ unsigned long _y = (unsigned long)(y); \ (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \ @@ -130,7 +142,11 @@ extern phys_addr_t phys_ram_base; }) #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) +#ifndef CONFIG_DEBUG_VIRTUAL #define linear_mapping_va_to_pa(x) ((unsigned long)(x) - kernel_map.va_pa_offset) +#else +phys_addr_t linear_mapping_va_to_pa(unsigned long x); +#endif #define kernel_mapping_va_to_pa(y) ({ \ unsigned long _y = (unsigned long)(y); \ (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < kernel_map.virt_addr + XIP_OFFSET) ? \ diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 225a7d2b65cc..fed5109d27db 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -213,6 +213,13 @@ static void __init setup_bootmem(void) phys_ram_end = memblock_end_of_DRAM(); if (!IS_ENABLED(CONFIG_XIP_KERNEL)) phys_ram_base = memblock_start_of_DRAM(); + + /* + * Any use of __va/__pa before this point is wrong as we did not know the + * start of DRAM before. + */ + kernel_map.va_pa_offset = PAGE_OFFSET - phys_ram_base; + /* * memblock allocator is not aware of the fact that last 4K bytes of * the addressable memory can not be mapped because of IS_ERR_VALUE @@ -667,9 +674,16 @@ void __init create_pgd_mapping(pgd_t *pgdp, static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) { - /* Upgrade to PMD_SIZE mappings whenever possible */ - base &= PMD_SIZE - 1; - if (!base && size >= PMD_SIZE) + if (!(base & (PGDIR_SIZE - 1)) && size >= PGDIR_SIZE) + return PGDIR_SIZE; + + if (!(base & (P4D_SIZE - 1)) && size >= P4D_SIZE) + return P4D_SIZE; + + if (!(base & (PUD_SIZE - 1)) && size >= PUD_SIZE) + return PUD_SIZE; + + if (!(base & (PMD_SIZE - 1)) && size >= PMD_SIZE) return PMD_SIZE; return PAGE_SIZE; @@ -978,11 +992,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) set_satp_mode(); #endif - kernel_map.va_pa_offset = PAGE_OFFSET - kernel_map.phys_addr; + kernel_map.va_pa_offset = 0UL; kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr; - phys_ram_base = kernel_map.phys_addr; - /* * The default maximal physical memory size is KERN_VIRT_SIZE for 32-bit * kernel, whereas for 64-bit kernel, the end of the virtual address @@ -1097,6 +1109,17 @@ static void __init setup_vm_final(void) __pa_symbol(fixmap_pgd_next), PGDIR_SIZE, PAGE_TABLE); +#ifdef CONFIG_STRICT_KERNEL_RWX + /* + * Isolate the kernel text and rodata linear so they don't + * get mapped with a PUD in the linear mapping. + */ + memblock_isolate_memory(__pa_symbol(_start), + __init_data_begin - _start); + memblock_isolate_memory(__pa_symbol(__start_rodata), + __start_rodata - _data); +#endif + /* Map all memory banks in the linear mapping */ for_each_mem_range(i, &start, &end) { if (start >= end) diff --git a/arch/riscv/mm/physaddr.c b/arch/riscv/mm/physaddr.c index 9b18bda74154..18706f457da7 100644 --- a/arch/riscv/mm/physaddr.c +++ b/arch/riscv/mm/physaddr.c @@ -33,3 +33,19 @@ phys_addr_t __phys_addr_symbol(unsigned long x) return __va_to_pa_nodebug(x); } EXPORT_SYMBOL(__phys_addr_symbol); + +phys_addr_t linear_mapping_va_to_pa(unsigned long x) +{ + BUG_ON(!kernel_map.va_pa_offset); + + return ((unsigned long)(x) - kernel_map.va_pa_offset); +} +EXPORT_SYMBOL(linear_mapping_va_to_pa); + +void *linear_mapping_pa_to_va(unsigned long x) +{ + BUG_ON(!kernel_map.va_pa_offset); + + return ((void *)((unsigned long)(x) + kernel_map.va_pa_offset)); +} +EXPORT_SYMBOL(linear_mapping_pa_to_va); diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d1a68b6d03b3..d14735a81301 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -887,12 +887,13 @@ const void * __init of_flat_dt_match_machine(const void *default_match, static void __early_init_dt_declare_initrd(unsigned long start, unsigned long end) { - /* ARM64 would cause a BUG to occur here when CONFIG_DEBUG_VM is - * enabled since __va() is called too early. ARM64 does make use - * of phys_initrd_start/phys_initrd_size so we can skip this - * conversion. + /* + * __va() is not yet available this early on some platforms. In that + * case, the platform uses phys_initrd_start/phys_initrd_size instead + * and does the VA conversion itself. */ - if (!IS_ENABLED(CONFIG_ARM64)) { + if (!IS_ENABLED(CONFIG_ARM64) && + !(IS_ENABLED(CONFIG_RISCV) && IS_ENABLED(CONFIG_64BIT))) { initrd_start = (unsigned long)__va(start); initrd_end = (unsigned long)__va(end); initrd_below_start_ok = 1;