From patchwork Thu Mar 16 13:17:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13177616 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 6336FC6FD19 for ; Thu, 16 Mar 2023 13:20:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFC13900008; Thu, 16 Mar 2023 09:20:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAC6A900002; Thu, 16 Mar 2023 09:20:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97485900008; Thu, 16 Mar 2023 09:20:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 84ED2900002 for ; Thu, 16 Mar 2023 09:20:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6011A41409 for ; Thu, 16 Mar 2023 13:20:25 +0000 (UTC) X-FDA: 80574820410.24.A1F462A Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by imf01.hostedemail.com (Postfix) with ESMTP id 7EBA640016 for ; Thu, 16 Mar 2023 13:20:23 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=L6eAT+sm; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.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=1678972823; 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=cNtcjIvt7Jcu6BbJu0k6G/sx5AHflabOU3bxX5prrUE=; b=Ek7cDidZ5S9Ri0dNA9qWwFfUdmuF0ULTM3mPaI6s4Fpzwa4iRdYlBHoeRIvR0z4DcIoMQE JHb8VW2QvNUzh89qdCJmmwrDj7wo3HQUJ6uMTmygb5kMI3ZrMwQJpk99fuGfRChJMAJU7a QKIHIc4yY5N+JLG804H7JMRj5HZQjjo= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=L6eAT+sm; spf=pass (imf01.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678972823; a=rsa-sha256; cv=none; b=fQjmMPu6HoowJKmdF6WDqTh2chC8e8B1jV/FGWuvWR5jAwCoH8vV2LWQdYpi34YYcYcGe1 IIaZyPbPbCO/JK7S31OSC1U5W3mnrFJT4FVWedtsZLGK1x23C2p1AS2AK4c0KNSFRm+9im Gz5QpHExbczVuecPUFDQgPKrcp8zyC0= Received: by mail-wr1-f44.google.com with SMTP id h17so1515312wrt.8 for ; Thu, 16 Mar 2023 06:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678972822; 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=cNtcjIvt7Jcu6BbJu0k6G/sx5AHflabOU3bxX5prrUE=; b=L6eAT+smuQGoJO4DezL+IdwC0T7yTp/6MdgBgpSYGnzsE3GMtH0OsHZCA5KvkK/jsL SCQbzTNJRG+h5gG55AwIc3rp3qvPJ5HvHBpBdMMvum+UhNDX3K0d4mevTt2us+FFR9fP /SkYJ3PFgwjlEeZJ4QPID/NaQDyD2lSqhEWFJsMLe0iYwjDfErv7L30D/hLJYYVSFfx7 jrT7h87/rKRPpMs9Aij8oJj9DBxmwR0E5LN3DULWfc0aFVYbJwTggaKYwjOlxm9f5rbi T0csEj0sYOg1wDUvvVEpshdAj9QA/fAZ/IJurP8+1WuNoMR3+2zSN2/cqzpGfR2FuvNh EyZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678972822; 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=cNtcjIvt7Jcu6BbJu0k6G/sx5AHflabOU3bxX5prrUE=; b=kvzezwXBjus+HG4smC5OovQXNWrBirTYnl77rhzFdrMG5kn7gGM+gQvjVI3JqCm/6W iA3dPr0kBpDYEjTYil+ZwGtC+xniwFuPlsLAPGSQtJ0eFctCiW54ovNJVuhHUAl7poil Wvetws5niO+TA2SXt2d3a2AQDY0Vl7gOIghqF/eCuit59d5dcreHpuA7g4FulFnIMoyi WmaRMOz48/IjD/wZaeNamOaoI4j6s8M0N0DN4MXlaGx5vngW1u8T3LbQc9BXU9J9ufIv sNJStz1A2TGcxWxqAOVrc86zRIXSRvAmTohg8apSQCNQ9IEvgwGnw3NwQfrVPtw7QulT 0e3g== X-Gm-Message-State: AO0yUKXvtlMosPD6UjYgiEusvQN9zXhOXzDbo4jGNHpIksoJdP4GrUEu 4W+SP0pHZeEkGRbWcB28/XHN+FMj+vyq9gAhJt8= X-Google-Smtp-Source: AK7set98CBvIraFbTCbJWdo8CgRP1gvKzH5/GyoF0yuADO0rA+pPToO5CbtwnI+LruqnMYg8TXy3Ww== X-Received: by 2002:adf:ce11:0:b0:2cf:e3d0:2a43 with SMTP id p17-20020adfce11000000b002cfe3d02a43mr4536359wrn.4.1678972821966; Thu, 16 Mar 2023 06:20:21 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (238.174.185.81.rev.sfr.net. [81.185.174.238]) by smtp.gmail.com with ESMTPSA id z4-20020a5d6544000000b002c56013c07fsm7218162wrv.109.2023.03.16.06.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 06:20:21 -0700 (PDT) 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 v8 3/4] arm64: Make use of memblock_isolate_memory for the linear mapping Date: Thu, 16 Mar 2023 14:17:10 +0100 Message-Id: <20230316131711.1284451-4-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230316131711.1284451-1-alexghiti@rivosinc.com> References: <20230316131711.1284451-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7EBA640016 X-Stat-Signature: tkbabafjsujcdgzw3nok7dq9y6efqpd6 X-Rspam-User: X-HE-Tag: 1678972823-685352 X-HE-Meta: U2FsdGVkX19gEJ2P6RCg89aCJBXtor0Nzg4/HNEo6GyIQTAzuSHOjgZPPe88WT+mlPvY8a3Zp/P08Lp0JENBWGeupRbsxdufI17cQuP69pPlXSEZLko0/ttQJejaC21fB52aiZS6j196hZF93+cAZpRsE8OLwc7RK668HjsZWImTemJ5YlRFnllfrcFWUE2jIIIlNFN+yC6kKrfS7lgl3WF25G9lmELwhyECb77pk1DMI296Q7ZinMxz/XNC/ZJvNxMxUfQ64096Ohcjl0iTPbWA9f8rUgiuG4wWU2qV0r3VZ0xstbKgr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eSVCymaDIbPJ63FoemPTMzjnnTsnFQgd3NBoQhtkEoMmS1OL48rInxnsGZH6GH1OtWoxZSjBhHCPQEw5dgL0RjOUQD8bNwqQ3djj7Kal9F/cvZsWIa22b+yNORg+eQDI2NbHzbP981A2ldJ9VDj4c5WckhOEo50YtLrjW3rPH+lpmqR1DPvMuOIO30RFU= 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 and the crash kernel region, we used some sort of hack to isolate thoses ranges which consisted in marking them 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 | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 6f9d8898a025..387c2a065a09 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -548,19 +548,18 @@ static void __init map_mem(pgd_t *pgdp) /* * Take care not to create a writable alias for the - * read-only text and rodata sections of the kernel image. - * So temporarily mark them as NOMAP to skip mappings in - * the following for-loop + * read-only text and rodata sections of the kernel image so isolate + * those regions and map them after the 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) { if (defer_reserve_crashkernel()) flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; else if (crashk_res.end) - memblock_mark_nomap(crashk_res.start, - resource_size(&crashk_res)); + memblock_isolate_memory(crashk_res.start, + resource_size(&crashk_res)); } #endif @@ -568,6 +567,17 @@ static void __init map_mem(pgd_t *pgdp) for_each_mem_range(i, &start, &end) { if (start >= end) break; + + if (start == kernel_start) + continue; + +#ifdef CONFIG_KEXEC_CORE + if (start == crashk_res.start && + crash_mem_map && !defer_reserve_crashkernel() && + crashk_res.end) + continue; +#endif + /* * The linear map must allow allocation tags reading/writing * if MTE is present. Otherwise, it has the same attributes as @@ -589,7 +599,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 @@ -603,8 +612,6 @@ static void __init map_mem(pgd_t *pgdp) crashk_res.end + 1, PAGE_KERNEL, NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS); - memblock_clear_nomap(crashk_res.start, - resource_size(&crashk_res)); } } #endif