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: 13169059 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 46083C6FD1C for ; Fri, 10 Mar 2023 09:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c66PYWwzRxHdatpvULD/PmlsKIYTa+gtTVAyANW9Vi4=; b=qzDNcXjPI8zWj8 OfIiykl8lqjJm9VhkGELEoQMRZ5iPOtSxeByo9eegKDUS2LyfgKLAnHlAVYaDRiSKCTCxDrH4bt3b 0ov1r9sYWt8Gi3q6Q2oQ6wDoB5D4nIrB831D2F5DpizUZXJA4n9In2kqsGMT/PZF/nTCno8ik+u7j a6LmC2ZDHN37VCwDSh5KG6TrmW9+CYcG6Dye/GFpQt6LzdKrOvgiqrzTSe7U/usCRe00T0J/t0g9J HYaXN2DqaeZDVLBooM3q12h7S8r+rBtBpUm3nAn5RZ8Mi9845nNFZjscXkBH4oN3axZqz5M2FRPtu FYwcYhuIxlh0+yrajuKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1paZLv-00E1bt-GT; Fri, 10 Mar 2023 09:47:55 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1paZLs-00E1XE-B8 for linux-arm-kernel@lists.infradead.org; Fri, 10 Mar 2023 09:47:53 +0000 Received: by mail-wm1-x32d.google.com with SMTP id t25-20020a1c7719000000b003eb052cc5ccso5553674wmi.4 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=l6x/Z7kWLwOumpLPTfeOeEV+SHzH7H7gztVXZnaXMK7RcQ0rasvl4a6U7N/wQ8/iwV dYEbyx9t9Wf8+FJxVMayhODAMzSDvgJ4MfQY982b+zEefTlkrn9hix91TYiuNhkkXNp+ AFbwBbvS1S4yC8SmEH+4Eah3lXb040JpTEw6lnZkx0nZ63KEH6P2dN7AO3d5d9n9X8Be XcWkcb1Tgo9wQZDYShUktRKYf02gcr41hE9oVvE1HeHFn1qp8ue/60AfWdustNrWGWzy EbmDSVnyL0lx2rufaxcTTGW/fOQcGfz/rbuw8yroFoyHRW6A05XyM1prDkTD1P4Xiv2l mGfw== X-Gm-Message-State: AO0yUKX79b+hRXMdYIrCfQTCpAz3Q/rFOdEjAGXFJlreioGlqHMShBZ5 On4PObRBucO+NMFnv9ZT1e2Ylg== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230310_014752_392420_9230F6F4 X-CRM114-Status: GOOD ( 15.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) {