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/Ip8d4OYAcIkUfkzI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nMlHrIYE2T9dZTmXz8XvFyXKptZlt4W3Q7ancCjc1ok18vBlSAe5G0etFxLi71+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) {