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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19AF7C6FD19 for ; Thu, 16 Mar 2023 13:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbjCPNUG (ORCPT ); Thu, 16 Mar 2023 09:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbjCPNUC (ORCPT ); Thu, 16 Mar 2023 09:20:02 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA731C0803 for ; Thu, 16 Mar 2023 06:19:22 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id l12so1504476wrm.10 for ; Thu, 16 Mar 2023 06:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678972760; 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=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=67doldxYgYKlU/XZ0kZu3+NOAqQ/2WbnP4mwdaTGI0McuaMhRPDAE/s74Wq3t6tF/V J0nRxluNtH5jyXjG6gwranylrEnecoP/DUWgaO9JZ4gg6xFffDGE08IwIc2KOUXaspal HHuTUIg4II4i6Oa5sRMFXG0qwnNOZQwEH5YClaHtl1ekxMRL+d17IM5dSSKvN8etH4o4 Gryhf8z+9DXYE61ol4wGcZdxrAPW2qatjZ5Q8iOQkHFCUmxFt43/+ApFfD1rBG+HZP3t j+M2PnF2oTfQycLOuf/WXwZevaBF66GgvGXiPTY9lyNMUBSV3fX9CsUSbPa1JK7AlIvp vKjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678972760; 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=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=yrx8mJNUc9+fkBJ8kREkaWFHaUzshiJKiOnk4nOqUpUSvMcvSNdzax6fHqs8PAxS9Y 64BB5FJk9Mc4A1XxWIDFR+xDO9sLjCLoqL2Ry0QI0iUS3RDywAuKD/AavVglQept6pv9 v6XT1ZfkBwGPT2L6g4cZA0WvMJERMsGaDJcE9rA4VZIVYbTGbedq6dxBiioDW4yBfaDi 4LQiaeQTfzttu12hT6rajxSklGwp8++Jb4hRCGaTXRIjIm3cc86FAQaMcEktmC9rFl7U 4fHze9yyMAF9RW3drJZuEsCLMaqsw5bIFZmghPE16Jh/M/K/fMt6lWP+FhvTp0HR66Fw dNZA== X-Gm-Message-State: AO0yUKXrRA7CF4GbKM7QYcOpGRs28SiGuLEx7ZM+9ueg4ULYUt20WblN 72+Fds1KZP6FRO/2viYHLM8U7w== X-Google-Smtp-Source: AK7set9ckwc+gnRj+k56d+SvgcefBu0ajEjl4o1f/HxCl/7FMrq5djA9ftFJ5OFMO4WJD/IRBsDEKA== X-Received: by 2002:a5d:49cc:0:b0:2c7:57e:633e with SMTP id t12-20020a5d49cc000000b002c7057e633emr4666191wrs.49.1678972760162; Thu, 16 Mar 2023 06:19:20 -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 h5-20020a5d5485000000b002c5a1bd5280sm7210070wrv.95.2023.03.16.06.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 06:19:20 -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 2/4] mm: Introduce memblock_isolate_memory Date: Thu, 16 Mar 2023 14:17:09 +0100 Message-Id: <20230316131711.1284451-3-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 Reviewed-by: Anup Patel Tested-by: Anup Patel --- include/linux/memblock.h | 1 + mm/memblock.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) 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..e8c651a37012 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type, return 0; } +/** + * memblock_isolate_memory - isolate given range in memblock.memory + * @base: base of range to isolate + * @size: size of range to isolate + * + * Isolates the given range in memblock.memory so that it does not share any + * region with other ranges. + * + * Return: + * 0 on success, -errno on failure. + */ + +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size) +{ + int start_rgn, end_rgn; + + return memblock_isolate_range(&memblock.memory, base, size, + &start_rgn, &end_rgn); +} + static int __init_memblock memblock_remove_range(struct memblock_type *type, phys_addr_t base, phys_addr_t size) { -- 2.37.2 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 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 0D806C74A5B for ; Thu, 16 Mar 2023 14:31:27 +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=7o3dy5n3CO0ld7kHCm/Ctl0Kl+L9QrpwOe+geFTA6SI=; b=a7JMw6CqydapBm xS0eRQn2AD5DTL7FHl8aACa4zkLvodeluY1DuJ6ddMUrEzktZJEonWTEZnZ+VtIfSrvWX5blIeov6 Qk7q7z8CPQO3ST5CNu5CXkN89a8XdWKDJpI01tFdH3t2MBDEgerIqKUUJrECu4j2KEDchuvJ79SHG 0+0HnQI2MhSYccQ8fiezx9gQyu++QzQhbkTk9yp5EdtalFdjFT9AWMK3StZFvgslntkHRMpNq5/9e Xr0hSxMWNeNKyPSkl0661QGNDkiMlhrDmi5zRymlHTXoSsLfqQPrkgVMmIfP4lmZVdBzd8T0mDzz6 2FLzgq+VMDZ4GF7YjqJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcodI-00Ggwq-0Z; Thu, 16 Mar 2023 14:31:08 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcnVq-00GVHn-1X for linux-riscv@lists.infradead.org; Thu, 16 Mar 2023 13:19:23 +0000 Received: by mail-wr1-x42a.google.com with SMTP id o7so1517643wrg.5 for ; Thu, 16 Mar 2023 06:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678972760; 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=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=67doldxYgYKlU/XZ0kZu3+NOAqQ/2WbnP4mwdaTGI0McuaMhRPDAE/s74Wq3t6tF/V J0nRxluNtH5jyXjG6gwranylrEnecoP/DUWgaO9JZ4gg6xFffDGE08IwIc2KOUXaspal HHuTUIg4II4i6Oa5sRMFXG0qwnNOZQwEH5YClaHtl1ekxMRL+d17IM5dSSKvN8etH4o4 Gryhf8z+9DXYE61ol4wGcZdxrAPW2qatjZ5Q8iOQkHFCUmxFt43/+ApFfD1rBG+HZP3t j+M2PnF2oTfQycLOuf/WXwZevaBF66GgvGXiPTY9lyNMUBSV3fX9CsUSbPa1JK7AlIvp vKjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678972760; 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=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=duzqXJzEpVqy8X0qqZACm+BgKdCeLqf3vXOnjzUi+/MrZJlla1TrvGwLZHu2GxC4zY C0qhfRcjq5m7ZAJFhueT9+EhsX1T7CfAjShgFSRmw3OEpDiHiWnGja8anWQL7cwH/pC9 kDBq0b9pc0OzjOj78v/gGt9f3K3AJf0Zf6ucjxvK/KaPuy0JUbasBYHTwu+kcKI05xLS RfpMZBnOS05L4EzDHfi1N6kLH91Y0Sv/CggKKSkdlFuYiGQbdKJaj1psrBU0EW+jvfLN A31jurfiseVsTHsaA2wd8VxEjrpnz8F4xQjXOCbCmdSAbJna20aE7gDlRr8Bg1X2nD2Z MkvQ== X-Gm-Message-State: AO0yUKVBSQCj7lsD1TRdDC4FRZ3ztkzt/BOs3PnaAyndrUZHtnLQAIPt gWZ1LXHpo82RudaxfaR7EgJogw== X-Google-Smtp-Source: AK7set9ckwc+gnRj+k56d+SvgcefBu0ajEjl4o1f/HxCl/7FMrq5djA9ftFJ5OFMO4WJD/IRBsDEKA== X-Received: by 2002:a5d:49cc:0:b0:2c7:57e:633e with SMTP id t12-20020a5d49cc000000b002c7057e633emr4666191wrs.49.1678972760162; Thu, 16 Mar 2023 06:19:20 -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 h5-20020a5d5485000000b002c5a1bd5280sm7210070wrv.95.2023.03.16.06.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 06:19:20 -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 2/4] mm: Introduce memblock_isolate_memory Date: Thu, 16 Mar 2023 14:17:09 +0100 Message-Id: <20230316131711.1284451-3-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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230316_061922_520852_C7094131 X-CRM114-Status: GOOD ( 11.30 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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 Reviewed-by: Anup Patel Tested-by: Anup Patel --- include/linux/memblock.h | 1 + mm/memblock.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) 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..e8c651a37012 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type, return 0; } +/** + * memblock_isolate_memory - isolate given range in memblock.memory + * @base: base of range to isolate + * @size: size of range to isolate + * + * Isolates the given range in memblock.memory so that it does not share any + * region with other ranges. + * + * Return: + * 0 on success, -errno on failure. + */ + +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size) +{ + int start_rgn, end_rgn; + + return memblock_isolate_range(&memblock.memory, base, size, + &start_rgn, &end_rgn); +} + static int __init_memblock memblock_remove_range(struct memblock_type *type, phys_addr_t base, phys_addr_t size) { -- 2.37.2 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 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 13FFCC6FD1F for ; Thu, 16 Mar 2023 14:32:01 +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=tsOBHGGCIq7FWbx3OVXYSTfVSD+U+ha0EByhxIV+iGo=; b=ipJxSb94Wd15Hj OFMauDLIj4d/pcrvZ+yO7sCsTR9Q3rNwb4YxmXUkzRtoIfjv353qxgnTbre8MClcvhTlhV4p8fPO2 4ncP6oTRMhLci6BoE43vyps9wYKwcGZuY6QbYx70kM8WhkKas+Sb2frYCpDgGDumL4bEK/RAUw2mG u7ciCYcsCzOwwiF+7Yf0FknXUZ91+4HmKzjvQ2ZeCa6MAWb7zHO1U24uUQWlhtamoJ9+lYpCH/IRw XLup7YlMbeNTl4631rJs+Xzy4AxRBPsLe7v034ru3qmHkEDrC4EBVTm3A7fMLvTWOLmz3r6bpq+QD hRr2j/dxMVUuJBtKO/nA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcodI-00Ggwv-2P; Thu, 16 Mar 2023 14:31:08 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcnVq-00GVHo-1Y for linux-arm-kernel@lists.infradead.org; Thu, 16 Mar 2023 13:19:23 +0000 Received: by mail-wr1-x434.google.com with SMTP id q16so1529857wrw.2 for ; Thu, 16 Mar 2023 06:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678972760; 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=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=67doldxYgYKlU/XZ0kZu3+NOAqQ/2WbnP4mwdaTGI0McuaMhRPDAE/s74Wq3t6tF/V J0nRxluNtH5jyXjG6gwranylrEnecoP/DUWgaO9JZ4gg6xFffDGE08IwIc2KOUXaspal HHuTUIg4II4i6Oa5sRMFXG0qwnNOZQwEH5YClaHtl1ekxMRL+d17IM5dSSKvN8etH4o4 Gryhf8z+9DXYE61ol4wGcZdxrAPW2qatjZ5Q8iOQkHFCUmxFt43/+ApFfD1rBG+HZP3t j+M2PnF2oTfQycLOuf/WXwZevaBF66GgvGXiPTY9lyNMUBSV3fX9CsUSbPa1JK7AlIvp vKjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678972760; 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=yXNicKwHPUURyALO36PEegj/jGCRXjX7/YBezTaryXs=; b=1YXEw2PS04A15tX13WjqGVc8CBJh55J8iDbtYzTzxkgOrejvqT8qSEqTHttIka6W8d XwWJIY6x+8VROUcIUVzLFxLiSBjm5XlFGO23KzRh4vR5zVdXxowEY4QZpLXSeHJQEGbd yvlekpPXZEVDWGj3+UCWZD9I4dlsbA9zM9tjOlcBHSN6FuyJgvMQ+upVs2nlEax2fuMk aE+dalfOyKU1AAav5RaHqf6iPPsndBVrRkKT7koVu8X9LXtRWTsusaXduuH7sU1OD8HU D6/Av2vka24Rg2fUEenMNLQQk9vyO8Csgj8DnT6+z7weY8rEHHIpxb+yI4s0ddH0uCZz G4Qg== X-Gm-Message-State: AO0yUKWhaLr2fydd28GVtgl7lSxMqMcKh5EbSbXm/DbCCOUR2Qa0Tyxi w/fCiP6t33tJyKpy2CuOsxgEkw== X-Google-Smtp-Source: AK7set9ckwc+gnRj+k56d+SvgcefBu0ajEjl4o1f/HxCl/7FMrq5djA9ftFJ5OFMO4WJD/IRBsDEKA== X-Received: by 2002:a5d:49cc:0:b0:2c7:57e:633e with SMTP id t12-20020a5d49cc000000b002c7057e633emr4666191wrs.49.1678972760162; Thu, 16 Mar 2023 06:19:20 -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 h5-20020a5d5485000000b002c5a1bd5280sm7210070wrv.95.2023.03.16.06.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 06:19:20 -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 2/4] mm: Introduce memblock_isolate_memory Date: Thu, 16 Mar 2023 14:17:09 +0100 Message-Id: <20230316131711.1284451-3-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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230316_061922_520717_178C47F2 X-CRM114-Status: GOOD ( 12.67 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 Reviewed-by: Anup Patel Tested-by: Anup Patel --- include/linux/memblock.h | 1 + mm/memblock.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) 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..e8c651a37012 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -805,6 +805,26 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type, return 0; } +/** + * memblock_isolate_memory - isolate given range in memblock.memory + * @base: base of range to isolate + * @size: size of range to isolate + * + * Isolates the given range in memblock.memory so that it does not share any + * region with other ranges. + * + * Return: + * 0 on success, -errno on failure. + */ + +int __init_memblock memblock_isolate_memory(phys_addr_t base, phys_addr_t size) +{ + int start_rgn, end_rgn; + + return memblock_isolate_range(&memblock.memory, base, size, + &start_rgn, &end_rgn); +} + static int __init_memblock memblock_remove_range(struct memblock_type *type, phys_addr_t base, phys_addr_t size) { -- 2.37.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel